0
我試圖在視圖上顯示網格,它給了我一個網格上的錯誤。這是視圖必須先綁定數據源,然後才能在MVC上執行此操作5
@{var grid = new WebGrid(Model, canPage: true, rowsPerPage: 20,
selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.NextPrevious);
ViewBag.Title = "Data results";
}
@{
ViewBag.Title = "Results";
Layout = "~/Views/Shared/_InternalLayout.cshtml";
}
<h2>Data Results</h2>
<div id="gridContent">
<p class="text-success">@ViewBag.Result</p>
<p class="text-danger">@Html.ValidationMessage("Error")</p>
@using (Html.BeginForm("ReportTable", "ControllerName", FormMethod.Get))
{
@grid.GetHtml(
tableStyle: "webGrid2 ReportTable",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("Number", "Destination", canSort: false),
grid.Column("Received", "Receive Time", canSort: false),
grid.Column("Message", "Message", canSort: false),
grid.Column("Resubmit", format: @<text><input class="chkbox" id="resubChkbx" name="ResubmitChkbx" type="checkbox" value="@item.ID" /></text>)
))}
</div>
這是控制器
public ActionResult ReportTable()
{
return View("ReportTable");
}
錯誤代碼,我得到的是這樣的:
數據源必須綁定此操作前可執行
And highlights @ grid.Gethtml
你還沒有告訴網格數據來自 – ADyson