0
这是我的问题。在我的页面上,我使用了从数据库中的各种表中拉出的几个webgrid。我遇到问题需要显示数据列。如果我将该列注释掉,网格将显示并必须更正该表中数据量的页数。如果我把这个列放回去,我得到那个列的名字不存在。这发生在所有网格上。因此,这里是代码的设置:MVC5 Webgrid问题
在控制器页面:
var cdb = new CommonModel();
IEnumerable<SelectListItem> _for = cdb.Formats
.OrderBy(f => f.FormatName)
.Select(f => new SelectListItem { Value = f.FormatID.ToString(), Text = f.FormatName });
ViewBag.Forma = _for;
在视图页面:
@model HomeInventory.Web.Areas.Classes.Video
@{
ViewBag.Title = "Add Movies/Television Shows";
Layout = "~/Views/Shared/_MovieLayout.cshtml";
}
@{
var fgrid = new WebGrid(source: ViewBag.Forma,
defaultSort: "FormatName",
rowsPerPage: 3, canSort: false,
pageFieldName: "pg");
}
@fgrid.GetHtml(tableStyle: "grid", columns: fgrid.Columns(fgrid.Column(format: (Formats) => Html.CheckBox("FormatID")), fgrid.Column("FormatName")))
@Html.ValidationMessageFor(model => model.Formats, "", new { @class = "text-danger" })
如果我运行的页面,我得到以下错误: 列“格式名称”不存在。该表格将其列为FormatName,但我也尝试过格式,格式和名称,其结果与该列不存在相同。很有可能我没有正确设置,导致此问题。有没有人看到我可能错过了什么?
谢谢你,更改为新的列表,它工作正常。 –