Home Export data as PDF Using JQuery In ASP.NET MVC
Reply: 0

Export data as PDF Using JQuery In ASP.NET MVC

user3162 Published in March 24, 2018, 2:25 am

I'm following C# corner article to bind data from controllers action to HTML table and then export data from HTML table to iTextSharp pdf. Below i'm binding controllers action method data to html table.

@model List<ExportDataAsPDFAppl.Controllers.Employees>  
@using (Html.BeginForm("exportPDF", "Home", FormMethod.Post))  
        <input type="hidden" name="gridHTML" />  
        <input type="submit" id="btnExportHTML" name="btnExportHTML" class="btn btn-success" value="Export Pdf" />  
    <div id="tblEmpData">  
        <table class="table table-striped table-condensed">  
                @foreach (var item in Model)  

In btnExportHTML jQuery click function, hidden variable gridHTML is binded with HTML table.

<script type="text/javascript">  
    $(document).ready(function () {  
        $('#btnExportHTML').click(function () {  

But on export 'btnExportHTML' click, HTTP 404 error is raised.

Below is action Method for button btnExportHTML click.

private FileResult exportPDF(string gridHTML)  
    StringReader reader = null;  
    Document pdfDoc = null;  
    PdfWriter write = null;  
        using (MemoryStream memorystream = new MemoryStream())  
            reader = new StringReader(gridHTML);  
            pdfDoc = new Document(PageSize.A4, 5f, 5f, 5f, 5f);  
            write = PdfWriter.GetInstance(pdfDoc, memorystream);  
            XMLWorkerHelper.GetInstance().ParseXHtml(write, pdfDoc, reader);  
            return File(memorystream.ToArray(), "application/pdf", Convert.ToString(DateTime.Now + ".pdf"));  


please let me know my mistake to solve this issue.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.428047 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO