【问题标题】:DevExpress Gridview MVC : where do you place events of the gridview?DevExpress Gridview MVC:你在哪里放置gridview的事件?
【发布时间】:2013-09-19 08:16:07
【问题描述】:

我正在使用 DevExpress 的网格视图进行 MVC 项目。

我是 MVC 和 DevExpress 的新手。

在每种 gridview 的项目中: - 我有一个模型可以访问数据库并返回数据列表 -我有一个将模型传递给相关视图的控制器。 -我有一个显示和排序绑定模型的数据的网格视图。 gridview 需要几个事件来正确显示未绑定列的数据,显示组合框过滤器行等......

我用编码来定义gridview(我不知道我做的是对还是错,你能确认一下吗?)

就像:

GridViewSettings settings = new GridViewSettings();
settings.Name = "grid";
....
  //this event to strike the disabled objects in the grid
settings.HtmlRowPrepared = ((project.Models.theModel)Model).gridUsers_htmlRowPrepared;
.....
//And now i render the gridview and i bind it to the list of objects
     Html.DevExpress().GridView(settings). Bind(((project.Models.theModel)Model).getListOfObjects()).Render();

如您所见,目前,我的事件被放置在模型中。

MVC 的方式是将数据处理与视图分离。

我的模型存储了修复我的网格视图显示的方法:这根本不像 MVC。

您如何管理您的活动?你把它们放在哪里?

请记住,在项目中,我只能从模型中访问数据库的对象(这就是为什么我将事件放在模型中,以使其更容易)。

提前感谢您的回答... Gridview MVC 对我来说是一个挑战。

【问题讨论】:

    标签: asp.net-mvc events model devexpress


    【解决方案1】:

    如果我没有误会,我添加了一个 GridView 示例,

    @Html.DevExpress().GridView(
    settings =>
    {
        settings.Name = "gvFilterRow";
        settings.CallbackRouteValues = new { Controller = "GridView", Action = "FilterRowPartial" };
        settings.Width = Unit.Percentage(100);
    
        settings.Columns.Add("ProductName");
        settings.Columns.Add(column => {
            column.FieldName = "CategoryID";
            column.Caption = "Category";
    
            column.ColumnType = MVCxGridViewColumnType.ComboBox;
            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
            comboBoxProperties.DataSource = NorthwindDataProvider.GetCategories();
            comboBoxProperties.TextField = "CategoryName";
            comboBoxProperties.ValueField = "CategoryID";
            comboBoxProperties.ValueType = typeof(int);
            comboBoxProperties.DropDownStyle = DropDownStyle.DropDown;
        });
    
    
        settings.Columns.Add("QuantityPerUnit");
        settings.Columns.Add("UnitPrice").PropertiesEdit.DisplayFormatString = "c";
        settings.Columns.Add("ReorderLevel");
        settings.Columns.Add("Discontinued", MVCxGridViewColumnType.CheckBox);
    
        settings.Settings.ShowFilterRow = true;
        settings.Settings.ShowFilterRowMenu = true;
        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ClearFilterButton.Visible = true;
    }).Bind(Model).GetHtml()
    

    【讨论】:

    • 亲爱的用户2791307你好。不幸的是,我看不到您在 gridview 示例中管理事件。事件类似于 "HtmlRowPrepared" 或 "RowValidating" 或 "CustomUnboundColumnData" 。这些事件需要方法:你把这些方法放在哪里?你从哪里称呼他们?
    猜你喜欢
    • 2012-07-11
    • 2020-08-23
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 2011-12-20
    • 2014-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多