【发布时间】:2015-07-21 05:10:59
【问题描述】:
这是我的问题。在我的页面上,我使用了几个从数据库中的各种表中提取的 webgrids。我在获取要显示的数据的列时遇到问题。如果我注释掉该列,网格将显示并且必须根据该表中的数据量更正页数。如果我将该列放回原处,我会得到该列的名称不存在。所有网格都在发生这种情况。所以这里是代码的设置:
在控制器页面上:
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,但我也尝试了 Format、Formats 和 Name,结果与该列不存在的结果相同。很有可能我没有正确设置某些东西,导致了这个问题。有人看到我可能错过了什么吗?
【问题讨论】:
标签: asp.net-mvc-5 webgrid