Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 480.9k

Extraction list to filter different records from db in asp.net mvc

Apr 17 2021 8:28 AM
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
  1. public IList < ScheduleManModel > GetScheduleManList()  
  2. {  
  3. DbAccessContext db = new DbAccessContext();  
  4. var scheduleList = (from e in db.ScheduleMan join d in db.ScheduleTbl on e.ScheduleId equals d.YearTblId select new ScheduleManModel {  
  5. Year = e.Year,  
  6. Week = e.Week,  
  7. 250 Buck = (int) e.250 Buck,  
  8. RACS = e.RACS,  
  9. YBR250 = d.YBR250  
  10. }).ToList();  
  11. return scheduleList;  
  12. }  
  13. public ActionResult ExtractionToExcel() {  
  14. var gv = new GridView();  
  15. gv.DataSource = this.ScheduleManList();  
  16. gv.DataBind();  
  17. Response.ClearContent();  
  18. Response.Buffer = true;  
  19. Response.AddHeader("content-disposition""attachment; filename=DemoExcel.xls");  
  20. Response.ContentType = "application/ms-excel";  
  21. Response.Charset = "";  
  22. StringWriter objStringWriter = new StringWriter();  
  23. HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter);  
  24. gv.RenderControl(objHtmlTextWriter);  
  25. Response.Output.Write(objStringWriter.ToString());  
  26. Response.Flush();  
  27. Response.End();  
  28. return View("Index");  
  29. }  
  30. }  
  31. }  
  1. @using (Html.BeginForm("ExportToExcel""Schedule", FormMethod.Post))  
  2. {  
  3. <br />  
  4. <br />  
  5. <h2>  
  6. Extraction Button  
  7. </h2>  
  8. <table style="background-color: white; width: 100%;">  
  9. <tr>  
  10. <th style="border: 1px solid black; text-align: left; width: 20%; padding-left: 20px;">  
  11. Year  
  12. </th>  
  13. <th style="border: 2px solid black; text-align: center; width: 20%">  
  14. Week  
  15. </th>  
  16. <th style="border: 2px solid black; text-align: center; width: 20%">  
  17. RACS  
  18. </th>  
  19. <th style="border: 2px solid black; text-align: center; width: 20%">  
  20. 270 Buck  
  21. </th>  
  22. <th style="border: 2px solid black; text-align: center; width: 20%">  
  23. 250 Buck  
  24. </th>  
  25. </tr>  
  26. @foreach (var itm in Model)  
  27. {  
  28. <tr>  
  29. <td colspan="4">  
  30. <br />  
  31. <br />  
  32. <input type="submit" value="Extraction" class="button" />  
  33. </td>  
  34. </tr>  
  35. </table>  
Using asp.net mvc to export them as excel, has anyone ever worked on that before?

Answers (2)