如何在不使用静态变量的情况下为每个回调函数维护devexpress gridview数据

时间:2014-03-06 11:08:45

标签: asp.net-mvc gridview devexpress

我为datagrid编写了以下代码。 控制器:

public class EmployeeController : BaseController
{
    public static List<EmployeeModel> Employees { get; set; }
    public ActionResult EmployeeSearchPartial()
    {
        return PartialView("EmployeeSearchPartial", Employees);
    }
}

EmployeeSearch部分视图

@Html.DevExpress().GridView(
settings =>
{
    settings.Name = "gvEmployeeSearch";
    settings.KeyFieldName = "EmployeeId";
    settings.SettingsPopup.EditForm.Width = 600;
    settings.CallbackRouteValues = new { Controller = "Employee", Action = "EmployeeSearchPartial" };
    settings.Width = 720;
    settings.Height = 600;
    settings.SettingsPager.PageSize = 15;
    settings.Settings.VerticalScrollBarStyle = DevExpress.Web.ASPxGridView.GridViewVerticalScrollBarStyle.Standard;
    settings.Settings.VerticalScrollableHeight = 350;
    settings.ControlStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
    settings.ControlStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
    settings.ControlStyle.BorderBottom.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
    settings.SettingsText.EmptyDataRow = "";
    settings.SettingsBehavior.AllowFocusedRow = true;
    settings.ClientSideEvents.RowClick = "OnCellClick";
    settings.Columns.Add(column =>
    {
        column.Caption = "Employee Name";
        column.FieldName = "Name";
        column.Width = 420;
    });
    settings.Columns.Add(column =>
    {
        column.Caption = "Employee Number";
        column.FieldName = "EmployeeId";
        column.Width = 300;
    });      
}).Bind(Model).GetHtml()

现在在上面的代码中,网格使用回调函数进行排序,过滤任何其他功能。当网格调用回调函数时,会为EmployeeController创建一个新对象,以便维护员工数据库(Employees)。我们必须在控制器中创建一个静态变量来维护网格数据分组列表。单个用户可以,但是当多个用户访问该页面时,网格值会发生冲突,因为MVC是一个Web应用程序,因此多个用户可以同时访问同一页面。

请分享任何解决方案以维护每个回叫功能的网格视图数据。

0 个答案:

没有答案