Hi
I am trying to export table to excel below is my code, its working in chrome but not in IE. I am using MVC 5
Controller code:
public ActionResult Index()
{
return View(db.tbl_GR_Reports.ToList());
}
public ActionResult ExportData()
{
GridView gv = new GridView();
gv.DataSource = db.tbl_GR_Reports.ToList();
gv.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=list.xls");
Response.ContentType = "application/ms-excel";
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("tbl_GR_Reports");
}
View Code:
@model IEnumerable
@{
ViewBag.Title = "Index";
}
Index
@Html.ActionLink("Create New", "Create")
@Html.DisplayNameFor(model => model.Report_Name) | @Html.DisplayNameFor(model => model.Description) | @Html.DisplayNameFor(model => model.Query) |
|---|---|---|
@Html.DisplayFor(modelItem => item.Report_Name) | @Html.DisplayFor(modelItem => item.Description) | @Html.DisplayFor(modelItem => item.Query) |
@using (Html.BeginForm("ExportData", "tbl_GR_Reports", FormMethod.Post))
{
}
Thanks,
Replies
Know the answer? Post it — somebody with the same question will find it here.