hi i am getting this error A data source must be bound before this operation can be performed,i am getting error on view i.e grid part
this is model code
using FT.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace FT.Models
{
public class ReportGenerationModel
{
List<VmsTypeDetailModel> getreportcategorylist;
List<AppointmentModel> serachedAppointmentModelList;
public ReportGenerationModel()
{
getreportcategorylist = new List<VmsTypeDetailModel>();
serachedAppointmentModelList = new List<AppointmentModel>();
}
public int Id { get; set; }
public string EmployeeId { get; set; }
public string UserName { get; set; }
public string TypeMasterName { get; set; }
public Nullable<System.DateTime> RecurringToDateTime { get; set; }
public Nullable<System.DateTime> RecurringFromDateTime { get; set; }
public string VisitingDepartmentName { get; set; }
public string ReasonForVisit { get; set; }
public string ContactPersonName { get; set; }
public Nullable<System.TimeSpan> VisitorCheckInTime { get; set; }
public Nullable<System.TimeSpan> VisitorCheckOutTime { get; set; }
public string CompanyName { get; set; }
public List<VmsTypeDetailModel> ReportcategoryList
{
get
{
return getreportcategorylist;
}
set
{
getreportcategorylist = value;
}
}
public List<AppointmentModel> SerachedAppointmentModelList
{
get
{
return serachedAppointmentModelList;
}
set
{
serachedAppointmentModelList = value;
}
}
public AppointmentModel Appointment { get; set; }
public VisitorModel Visitor { get; set; }
public List<DptWise> DptWiseReport { get; set; }
}
public class DptWise
{
public string VisitingDepartmentName { get; set; }
public string ReasonForVisit { get; set; }
public string ContactPersonName { get; set; }
public Nullable<System.TimeSpan> VisitorCheckInTime { get; set; }
public Nullable<System.TimeSpan> VisitorCheckOutTime { get; set; }
public string CompanyName { get; set; }
}
}
</pre>
this is controller code
public ActionResult VMSReports()
{
ReportGenerationModel reportGenerationModel = new ReportGenerationModel();
reportGenerationModel = this._iEmailConfigurationService.GetReportList();
return View(reportGenerationModel);
}
[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult VMSReports(ReportGenerationModel GetreportGenerationModel)
{
GetreportGenerationModel.ReportcategoryList = this._iEmailConfigurationService.GetReportList().ReportcategoryList;
if (GetreportGenerationModel.TypeMasterName == "101")
{
List<ReportGenerationModel> reportGenerationModel = this._iEmailConfigurationService.GetReportDetails(GetreportGenerationModel);
List<DptWise> lstDptwise = new List<DptWise>();
foreach (ReportGenerationModel item in reportGenerationModel)
{
lstDptwise.Add(new DptWise { CompanyName = item.CompanyName, ContactPersonName = item.ContactPersonName, ReasonForVisit = item.ReasonForVisit, VisitingDepartmentName = item.VisitingDepartmentName, VisitorCheckInTime = item.VisitorCheckInTime, VisitorCheckOutTime = item.VisitorCheckOutTime });
}
GetreportGenerationModel.DptWiseReport = lstDptwise;
}
return View(GetreportGenerationModel);
}
view code
@using GridMvc.Html
@{
ViewBag.Title = "VMSReports";
Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
// var grid = new WebGrid(Model.SerachedAppointmentModelList, defaultSort: "Id", rowsPerPage: 9);
var grid = new WebGrid(Model.DptWiseReport, defaultSort: "VisitingDepartmentName", rowsPerPage: 9);
// var grid = new WebGrid(Model, rowsPerPage: 9);
}
</pre>
<div id="gridContent" style="padding: 20px;">
@grid.GetHtml(
tableStyle: "gridTable",
headerStyle: "gridHead",
footerStyle: "gridFooter",
rowStyle: "gridRow",
alternatingRowStyle: "gridAltRow",
columns:
grid.Columns(
grid.Column("DepartmentName", @Resources.Appointment.VisitingDepartmentName, format: @<text> <span class="display-mode">@item.VisitingDepartmentName</span></text>, style: "col1Width"),
grid.Column("To", @Resources.Appointment.RecurringToDateTime, format: @<text> <span class="display-mode">@Model.RecurringToDateTime</span> </text>, style: "col2Width"),
grid.Column("From", @Resources.Appointment.RecurringFromDateTime, format: @<text> <span class="display-mode">@Model.RecurringFromDateTime</span></text>, style: "col1Width"),
grid.Column("Company Address", @Resources.Appointment.CompanyName, format: @<text> <span class="display-mode">@item.CompanyName</span> </text>, style: "col2Width"),
grid.Column("ContactPersonName", @Resources.Appointment.ContactPersonName, format: @<text> <span class="display-mode">@item.ContactPersonName</span></text>, style: "col3Width"),
grid.Column("ReasonForVisit", @Resources.Appointment.ReasonForVisit, format: @<text> <span class="display-mode">@item.ReasonForVisit</span></text>, style: "col3Width"),
grid.Column("Intime", @Resources.Appointment.VisitorCheckInTime, format: @<text> <span class="display-mode">@item.VisitorCheckInTime</span></text>, style: "col3Width")
//grid.Column("Export to excel", format: @<text><button type="submit" class="btn btn-primary pull-right btn-sm RbtnMargin" onclick="location.href='@Url.Action("ViewAppointment", "Appointment", new { aId = Model.AppointmentID })'">@Resources.Appointment.View</button></text>)
))
</div>