【问题标题】:Kendoui DropDownList on grid with Ajax and paramter (ASP.NET MVC)带有 Ajax 和参数的网格中的 Kendo Ui DropDownList (ASP.NET MVC)
【发布时间】:2012-09-18 19:05:24
【问题描述】:

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

@(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 视图引擎的 ASP.NET MVC。

【问题讨论】:

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


    【解决方案1】:

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

    @(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() 数组...

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-06
      • 1970-01-01
      相关资源
      最近更新 更多