DevExpress:sender.GetSelectedFieldValues没有调用我的客户端回调

时间:2013-12-10 07:57:44

标签: asp.net asp.net-mvc asp.net-mvc-4 devexpress devexpress-mvc

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

enter image description here

它获取数据的表格如下:

表名:类别

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

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

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

enter image description here

我使用的是DevExpress文档网站上this example中显示的几乎相同的代码。

这是我的代码。

查看

<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上使用DevExpress Extensions v12.2.10.0 for ASP.NET MVC 4.

1 个答案:

答案 0 :(得分:3)

将GridView设置置于单独部分视图(without any other tags)。