我在使用相同模型的单个视图上有 2 个 WebGrid。现在的问题是,每当我对单个 webgrid 应用排序时,它也在对另一个 webgrid 进行排序。我正在使用 fieldNamePrefix 仍然有问题。这是我的代码:
第一个部分视图:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRMEvent.Models.CRM.DatabaseEntities.CRM_Dashboard_Requests>>" %>
<%
var grid = new WebGrid(source: Model, defaultSort: "CRM_ID",fieldNamePrefix:"grid2", canSort: true);%>
<%=
grid.GetHtml( htmlAttributes: new { id = "grid2" },tableStyle: "GridTable", headerStyle: "GridHeader", columns: grid.Columns(
grid.Column(columnName: "CRM_ID", header: "CRM ID", canSort: true),
grid.Column(columnName: "MDLNO", header: "MDLNO", canSort: true),
grid.Column(columnName: "EMP_Name", header: "Employee", canSort: true),
grid.Column(columnName: "SERVICE_TYPE", header: "Service Type", canSort: true),
grid.Column(columnName: "Requested_Amount", header: "Amount", canSort: true),
grid.Column(columnName: "Created_Date", header: "Date", canSort: true, format: item => item.Created_Date.ToString("dd-MM-yyyy"))
))
%>
第二部分视图:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<ApricaCRMEvent.Models.CRM.DatabaseEntities.CRM_Dashboard_Requests>>" %>
<%
var grid = new WebGrid(source: Model, defaultSort: "CRM_ID",fieldNamePrefix:"grid1", canSort: true);%>
<%=
grid.GetHtml( htmlAttributes: new { id = "grid1" },tableStyle: "GridTable", headerStyle: "GridHeader", columns: grid.Columns(
grid.Column(columnName: "CRM_ID", header: "CRM ID", canSort: true),
grid.Column(columnName: "MDLNO", header: "MDLNO", canSort: true),
grid.Column(columnName: "EMP_Name", header: "Employee", canSort: true),
grid.Column(columnName: "SERVICE_TYPE", header: "Service Type", canSort: true),
grid.Column(columnName: "Requested_Amount", header: "Amount", canSort: true),
grid.Column(columnName: "Created_Date", header: "Date", canSort: true, format: item => item.Created_Date.ToString("dd-MM-yyyy"))
))
%>