我在同一视图中使用两个webgrid。当我点击第二个gridview列时,排序工作完美,但是当我点击第一个GridView进行排序时,在第一个网格视图后添加第二个gridview的克隆。
这是我的代码:
<div class="x_content drop-shadow">
@{
var grid = new WebGrid(source: Model.MembershipList, canPage: true, rowsPerPage: 10, canSort: true, ajaxUpdateContainerId: "checkableGrid1", fieldNamePrefix: "g1",pageFieldName: "p1");
grid.Pager(WebGridPagerModes.All);
int rowVal = 0;
@grid.GetHtml(tableStyle: "table table-striped responsive-utilities jambo_table bulk_action", headerStyle: "headings", footerStyle: "webgrid-footer", alternatingRowStyle: "", rowStyle: "", htmlAttributes: new { id = "checkableGrid1" },
columns: grid.Columns(
grid.Column("Sr.No.", format: item => rowVal = rowVal + 1),
grid.Column(columnName: "ShopName", header: "Store Location"),
grid.Column(columnName: "MembershipTitle", header: "Membership Title"),
grid.Column(columnName: "MembershipTimeFrame", header: "TimeFrame[Days]"),
grid.Column(columnName: "MembershipMinVisit", header: "Minimum Visits"),
grid.Column(header: "Status", format: @<span style="cursor:pointer" id="@item.MembershipID" class="editButton"><u><i class="fa fa-pencil"></i>Edit</u></span>)
))
}
</div>
第二个GridView:
<div class="x_content drop-shadow">
@{
var gridReward = new WebGrid(source: Model.RewardList, canPage: true, rowsPerPage: 10, canSort: true, ajaxUpdateContainerId: "checkableGrid2", fieldNamePrefix: "g2",pageFieldName: "p2");
gridReward.Pager(WebGridPagerModes.All);
int rowVal1 = 0;
@gridReward.GetHtml(tableStyle: "table table-striped responsive-utilities jambo_table bulk_action", headerStyle: "headings", footerStyle: "webgrid-footer", alternatingRowStyle: "", rowStyle: "", htmlAttributes: new { id = "checkableGrid1" },
columns: gridReward.Columns(
gridReward.Column("Sr.No.", format: item => rowVal1 = rowVal1 + 1),
gridReward.Column(columnName: "Storename", header: "Store Location"),
gridReward.Column(columnName: "MembershipTitle", header: "Membership Title"),
gridReward.Column(columnName: "RewardPoints", header: "HighFive(s) Awarded"),
gridReward.Column(header: "Status", format: @<span style="cursor:pointer" id="@item.RewardID" class="editButton"><u><i class="fa fa-pencil"></i>Edit</u></span>)
))
}
</div>
这里我附上了网格视图的快照: http://prntscr.com/7iejw7 并在排序第一个GridView之后: http://prntscr.com/7iek6s