asp.net-mvc-3 - 带有 Ajax 和参数的网格中的 Kendo Ui DropDownList (ASP.NET MVC)

标签 asp.net-mvc-3 kendo-ui

我有一个使用下拉列表的 KendoUI 网格。所以网格的每个元素都有一个下拉列表。 DropDownList 在局部 View 中定义。

@(Html.Kendo().DropDownList()
    .Name("positions")
    .DataValueField("EmpId")
    .DataTextField("EmpName")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("_AjaxGetEmps", "Emp", new { Empid = <empid of currently selected grid row> });
        }).ServerFiltering(true);
    })
)

我把什么放在哪里?我想要做的是从当前选定行的网格中引用一个字段。网格的每一行在下拉列表中都可以有不同的值,我需要将值传递给 AjaxGetEmps 方法。我正在使用带有 Razor View 引擎的 ASP.NET MVC。

最佳答案

您必须通过 Empid通过 Data 方法传递参数,而不是像这样直接给出参数:

@(Html.Kendo().DropDownList()
    .Name("positions")
    .DataValueField("EmpId")
    .DataTextField("EmpName")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("_AjaxGetEmps", "Emp")
                .Data("getCurrentEmpid"); // this links to a javascript function 
                                          // which will get the current emp id
        }).ServerFiltering(true);
    })
)

并且 javascript 函数应该像这样实现:
function getCurrentEmpid() {
    var grid = $("#idGrid").data("kendoGrid"); // where "idGrid" is the id of your grid

    return {
        Empid: grid.dataItem(grid.select()).Empid
    }
}

这里grid.select()返回网格中选定的行和 grid.dataItem(row)获取与此行关联的数据。所以这里Empid应该是你的模型类的 id。
另请注意,如果您有标志 GridSelectionModeMultiple你将不得不循环抛出 grid.select()数组...

关于asp.net-mvc-3 - 带有 Ajax 和参数的网格中的 Kendo Ui DropDownList (ASP.NET MVC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12483358/

相关文章:

asp.net-mvc-3 - 使用 ASP MVC TempData 向用户显示消息时出现问题

javascript - 更改堆栈条形图中的起点

javascript - 如果启用了无限滚动,如何防止剑道网格两次加载数据?

asp.net-mvc - MVC调用Html.Action在区域内?

jquery - 将 qTip 与 MVC3 和 jQuery 验证集成 (errorPlacement)

c# - 如何使绑定(bind)到 Nullable<int> 属性的 DropDownListFor 接受空值?

c# - DropDownListFor 没有在 View 中获取所选项目,而是在 View 模型中

kendo-ui - 剑道图表分组/排序

asp.net-mvc-4 - KendoUI 设置下拉列表的宽度

javascript - 使用 Kendo 网格链接列过滤器