我是MVC的新手,我正在尝试从模型中检索数据并在Web Grid上显示,但问题是数据进入View但未在WebGrid中显示并显示错误 - 类型' System.InvalidOperationException'的例外情况发生在System.Web.Helpers.dll中但未在用户代码中处理 附加信息:专栏" empId"不存在。 这是我的代码 -
// // VIEW
@model IEnumerable<EmployeeModel.EmployeeList>
@{
ViewBag.Title = "List";
Layout = "~/Views/Shared/_Layout.cshtml";
WebGrid grid = new WebGrid(Model);
}
<div id="gridposition" style="width: 100%;">
@{
var grid1 = new WebGrid(source: Model, canPage: true, rowsPerPage: 10, ajaxUpdateContainerId: "gridContent");
@grid1.GetHtml(mode: WebGridPagerModes.All,
tableStyle: "gridTable",
headerStyle: "gridHead",
footerStyle: "gridFooter",
rowStyle: "gridRow",
alternatingRowStyle: "gridAltRow",
htmlAttributes: new { id = "positionGrid" },
fillEmptyRows: false,
columns: grid1.Columns(
grid1.Column("empId", header: "Id"),
grid1.Column("empName", header: "Name"),
grid1.Column("empAge", header: "Age"),
grid1.Column("empDob", header: "Dob"),
grid1.Column("addressCountry", header: "Country"),
grid1.Column("adsState", header: "State"),
grid1.Column("addDistrict", header: "District"),
grid1.Column("Qualification", header: "Qualification")))
}
</div>
// // MODEL
public class EmployeeList
{
public List<EmployeeDetails> EmpList { get; set; }
public List<EmailIdDetails> EmailList { get; set; }
public List<AddressDetail> AddList { get; set; }
public List<QualificationDetail> QualList { get; set; }
}