Damodar A

Damodar A

  • NA
  • 46
  • 30.3k

Export Grid to Pdf Using Mvc4

Apr 14 2014 1:51 AM
    public ActionResult ExportPdf()
        {
            GridView gv = new GridView();
            gv.DataSource = fetch();
            gv.DataBind();
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=list.pdf");
            Response.ContentType = "application/pdf";
            Response.Charset = "";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            gv.RenderControl(htw);
           
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

            return RedirectToAction("Index");
        }

Answers (1)