0

我有一个GridExtension看起来像这样的 MVC:

在此处输入图像描述

它从中获取数据的表如下所示:

表名:类别

Id    Name
--------------
1     Foo
2     Bar
3     Gar
4     Har

当我从网格中选择一行或多行并单击顶部的删除按钮时,我希望我的DeleteSelectedCategories处理程序应该被调用,这确实发生了。

但是,在DeleteSelectedcategories处理程序中,当我调用gvCategories.GetSelectedFieldValues为其提供客户端回调的方法时DeleteCategories,该方法不会被调用。相反,我将所有脚本代码显示在消息框中,如下所示:

在此处输入图像描述

我使用的代码与 DevExpress 文档网站上此示例中显示的代码几乎相同。

这是我的代码。

看法

<script type = "text/javascript">
//<![CDATA[
    $(document).ready(
        function () {
            WireHandlers();
        }
    );

        function DeleteCategories(selectedCategoriesArray) {

            debugger;

            if (selectedCategoriesArray.length == 0) return;

            for (var i = 0; i < selectedCategoriesArray.length; i++) {
                debugger;
            }
        }

        function DeleteSelectedCategories() {
            // debugger;

            if (gvCategories.GetSelectedRowCount() == 0) return;

            gvCategories.GetSelectedFieldValues('Id', DeleteCategories);
        }

        function WireHandlers() {
            $('#btnDeleteCategory').click(DeleteSelectedCategories);
        }
// ]]>
</script>

@using System.Web.UI.WebControls;
@using System.Data;
@model IEnumerable<GlobalizationUI.BusinessObjects.Category>

@Html.DevExpress().GridView(settings =>
    {
        settings.Name = "gvCategories";

        settings.CallbackRouteValues = new { Controller = "Category", Action = "CategoriesPartial" };

        settings.Width = 1200;

        settings.SettingsPager.Position = PagerPosition.TopAndBottom;
        settings.SettingsPager.FirstPageButton.Visible = true;
        settings.SettingsPager.LastPageButton.Visible = true;
        settings.SettingsPager.PageSizeItemSettings.Visible = true;
        settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50", "100", "200" };
        settings.SettingsPager.PageSize = 50;

        settings.Settings.ShowFilterRow = true;
        settings.Settings.ShowFilterRowMenu = true;

        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ClearFilterButton.Visible = true;
        settings.CommandColumn.ShowSelectCheckbox = true;

        settings.Settings.ShowHeaderFilterButton = true;

        settings.KeyFieldName = "Id";

        settings.Columns.Add("Name");

        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Category", Action = "CreateNew" };
        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Category", Action = "Edit" };

        settings.SettingsEditing.Mode = GridViewEditingMode.Inline;

        settings.CommandColumn.Visible = true;
        settings.CommandColumn.NewButton.Visible = true;
        settings.CommandColumn.EditButton.Visible = true;
        settings.CommandColumn.UpdateButton.Visible = true;

    }).Bind(Model).GetHtml()

我在 Windows 7 Home Premium 上为 ASP.NET MVC 4 使用 DevExpress Extensions v12.2.10.0。

4

1 回答 1

3

将 GridView 设置放到单独的PartialView 中(没有任何其他标签)。

于 2013-12-10T13:15:02.053 回答