我可以在 asp.net mvc 中使用两个 webgrids
Can i use two webgrids in asp.net mvc
我关注了这个linkhttp://www.codeproject.com/Tips/615776/WebGrid-in-ASP-NET-MVC
这对单个 webgrid 很好,但是如果我在同一页面中创建两个具有不同列数的 webgrid,我会收到错误如何解决这个问题
@{
var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5,
selectionFieldName: "selectedRow",ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.NextPrevious);}
<div id="gridContent">
@grid.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("Id", format: (item) => item.GetSelectLink(item.Id)),
grid.Column("Name", format: (item) => item.GetSelectLink(item.Name)),
grid.Column("Description", "Description", style: "description")
))
</div>
@{
var gridsecond = new WebGrid(Model, canPage: true, rowsPerPage: 5,
selectionFieldName: "selectedRow", ajaxUpdateContainerId: "secondgridContent");
grid.Pager(WebGridPagerModes.NextPrevious);}
<div id="secondgridContent">
@gridsecond.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: gridsecond.Columns(
gridsecond.Column("Id", format: (item) => item.GetSelectLink(item.Id)),
gridsecond.Column("Name", format: (item) => item.GetSelectLink(item.Name)),
gridsecond.Column("Description", "Description", style: "description"),
gridsecond.Column("Quantity", "Quantity")
))
</div>
当您在同一页面上有多个 WebGrid 时,您需要为每个 WebGrid 提供唯一的 FieldNamePrefix
和 PageFieldName
值。你可以通过它的构造函数来做到这一点:
var grid1 = new WebGrid(Model1, fieldNamePrefix: "g1", pageFieldName: "p1");
var grid2 = new WebGrid(Model2, fieldNamePrefix: "g2", pageFieldName: "p2");
我关注了这个linkhttp://www.codeproject.com/Tips/615776/WebGrid-in-ASP-NET-MVC 这对单个 webgrid 很好,但是如果我在同一页面中创建两个具有不同列数的 webgrid,我会收到错误如何解决这个问题
@{
var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5,
selectionFieldName: "selectedRow",ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.NextPrevious);}
<div id="gridContent">
@grid.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("Id", format: (item) => item.GetSelectLink(item.Id)),
grid.Column("Name", format: (item) => item.GetSelectLink(item.Name)),
grid.Column("Description", "Description", style: "description")
))
</div>
@{
var gridsecond = new WebGrid(Model, canPage: true, rowsPerPage: 5,
selectionFieldName: "selectedRow", ajaxUpdateContainerId: "secondgridContent");
grid.Pager(WebGridPagerModes.NextPrevious);}
<div id="secondgridContent">
@gridsecond.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: gridsecond.Columns(
gridsecond.Column("Id", format: (item) => item.GetSelectLink(item.Id)),
gridsecond.Column("Name", format: (item) => item.GetSelectLink(item.Name)),
gridsecond.Column("Description", "Description", style: "description"),
gridsecond.Column("Quantity", "Quantity")
))
</div>
当您在同一页面上有多个 WebGrid 时,您需要为每个 WebGrid 提供唯一的 FieldNamePrefix
和 PageFieldName
值。你可以通过它的构造函数来做到这一点:
var grid1 = new WebGrid(Model1, fieldNamePrefix: "g1", pageFieldName: "p1");
var grid2 = new WebGrid(Model2, fieldNamePrefix: "g2", pageFieldName: "p2");