在Razor中,我使用ADO.NET List绑定了Web Grid。然后,如果清空列表,我需要将Web Grid设置为false。请帮帮我
答案 0 :(得分:1)
只需测试模型对象的空值即可。见下面的工作代码:
@{
if(Model != null)
{
var grid = new WebGrid(Model.ToList),canPage:true, rowsPerPage: 15,
selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.All);
<div id="gridContent">
@grid.GetHtml(tableStyle: "webGrid",
headerStyle: "blue-gradient",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
//grid.Column(null,null, format: @<input type="hidden" name="IDHidden" value="@item.EventID"/>),
//grid.Column("", format: @<text>@Html.ActionLink("Select", "Submit", new { CaseId = item.File_Number }) </text>),
grid.Column("File_Number", "File Number", format: @<text>@Html.ActionLink(((string)item.File_Number), "Review", new { CaseId = item.File_Number }) </text>),
grid.Column("File_Name", "File Name"),
grid.Column("Attorney", "Attorney"),
grid.Column("Reviewer", "Reviewer"),
grid.Column("Department", "Department"),
grid.Column("Review_Status", "Review Status"),
grid.Column("Claim_Number", "Claim Number"),
grid.Column("Status", "Case Status")
))
</div>
}
}
Test for nulls and then if true, simply don't render the WebGrid at all