I want to export the Excel sheet of my Razor view table. This code shows the table:
public ActionResult Show(int id)
{
IEnumerable<GradeSheetViewModel> model = _repGrade.GetList(id);
return View(model);
}
Here is the code for export to Excel function
public ActionResult ExportToExcel()
{
var gv = new GridView();
gv.DataSource = this.Show();
gv.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=DemoExcel.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter objStringWriter = new StringWriter();
HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter);
gv.RenderControl(objHtmlTextWriter);
Response.Output.Write(objStringWriter.ToString());
Response.Flush();
Response.End();
return View("Index");
}
but it gives the error at
gv.DataSource = this.Show();
the error is
no overload for the method Show takes 0 argument