Hi Team
I have a button, but i want to know how can i extract the list of records from the button itself when clicked
- public IList < ScheduleManModel > GetScheduleManList()
- {
- DbAccessContext db = new DbAccessContext();
- var scheduleList = (from e in db.ScheduleMan join d in db.ScheduleTbl on e.ScheduleId equals d.YearTblId select new ScheduleManModel {
- Year = e.Year,
- Week = e.Week,
- 250 Buck = (int) e.250 Buck,
- RACS = e.RACS,
- YBR250 = d.YBR250
- }).ToList();
- return scheduleList;
- }
- public ActionResult ExtractionToExcel() {
- var gv = new GridView();
- gv.DataSource = this.ScheduleManList();
- 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");
- }
- }
- }
- @using (Html.BeginForm("ExportToExcel", "Schedule", FormMethod.Post))
- {
- <br />
- <br />
- <h2>
- Extraction Button
- </h2>
- <table style="background-color: white; width: 100%;">
- <tr>
- <th style="border: 1px solid black; text-align: left; width: 20%; padding-left: 20px;">
- Year
- </th>
- <th style="border: 2px solid black; text-align: center; width: 20%">
- Week
- </th>
- <th style="border: 2px solid black; text-align: center; width: 20%">
- RACS
- </th>
- <th style="border: 2px solid black; text-align: center; width: 20%">
- 270 Buck
- </th>
- <th style="border: 2px solid black; text-align: center; width: 20%">
- 250 Buck
- </th>
- </tr>
- @foreach (var itm in Model)
- {
- <tr>
- <td colspan="4">
- <br />
- <br />
- <input type="submit" value="Extraction" class="button" />
- </td>
- </tr>
- </table>
Using asp.net mvc to export them as excel, has anyone ever worked on that before?