我需要通过嘴巴进行不同的记录,但我有一个错误:
列“数据”不存在。
Server Error in '/' Application.
Column "data" does not exist.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Column "data" does not exist.
Source Error:
Line 14: var grid = new WebGrid(ViewBag.dat ,null, "Dates", 8);
Line 15: }
Line 16: @grid.GetHtml(
Line 17: tableStyle: "grid",
Line 18: headerStyle: "head",
我的控制器:
var d = (from b in baza.hours
where b.userID == userID
select new { b.data.Month }).Distinct();
ViewBag.dat = d;
我的观点:
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
@{
var grid = new WebGrid(ViewBag.dat ,null, "Dates", 8);
}
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("data","Dates")
)
)
</fieldset>
}
如何解决?
答案 0 :(得分:0)
试试这样:
grid.Column("Month", "Dates")
您正在向视图返回一个匿名对象。或者更准确地说是一组匿名对象,每个对象都有一个名为Month
的属性。因此,您应该在标记中使用Month
作为列名。