Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to exporting the data from webgrid to excel i am working with mvc5
C#
public ActionResult VMSReports(ReportGenerationModel GetreportGenerationModel,string command)
        {
           GetreportGenerationModel.ReportcategoryList = this._iEmailConfigurationService.GetReportList().ReportcategoryList;
         
           List<dptwise> lstDptwise = new List<dptwise>();
           if (command == "excel")
           {
               List<reportgenerationmodel> reportGenerationModel = this._iEmailConfigurationService.GetReportDetails(GetreportGenerationModel);
                //lstDptwise = lstDptwise.OrderBy(m => m.RecurringFromDateTime).ToList();
               // List<empwise> lstEmpwise = new List<empwise>();
               WebGrid wd = new WebGrid(source: lstDptwise, canPage: false, canSort: false);
               string griddata = wd.GetHtml(
       columns: wd.Columns
       (
       wd.Column(columnName: "VisitingDepartmentName", header: "DepartmentName"),
       wd.Column(columnName: "RecurringToDateTime", header: "To"),
       wd.Column(columnName: "RecurringFromDateTime", header: "From"),
       wd.Column(columnName: "VisitorName", header: "VisitorName"),
       wd.Column(columnName: "CompanyName", header: "CompanyName"),
       wd.Column(columnName: "ContactPersonName", header: "ContactPersonName"),
       wd.Column(columnName: "ReasonForVisit", header: "ReasonForVisit"),
       wd.Column(columnName: "VisitorCheckInTime", header: "Intime"),
       wd.Column(columnName: "VisitorCheckOutTime", header: "Outtime")

       )
       ).ToString();

               Response.Clear();
               Response.AddHeader("content-disposition", "attachment; filename=DepartmentWiseReport.xls");
               
               Response.ContentType = "application/excel";
               Response.Write(griddata);
               Response.End();
               return Redirect("lstDptwise");
              
           }

this is my code i am excel sheet with these heading but i didnt get data whatever these headers contains. please help me
Posted
Updated 1-Sep-15 1:42am
v2
Comments
Maciej Los 1-Sep-15 7:51am    
Why webgrid? Export data!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900