Kendoui的DropDownList与Ajax和放慢参数格(ASP.NET MVC) [英] Kendoui DropDownList on grid with Ajax and paramter (ASP.NET MVC)

查看:264
本文介绍了Kendoui的DropDownList与Ajax和放慢参数格(ASP.NET MVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a KendoUI grid that uses a DropDown List. So each element of the grid has a dropdown list. The DropDownList is defined in a partial 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方法。我使用ASP.NET MVC剃刀视图引擎。

What do I put where is? What I'm trying to do is reference a field from the grid of the currently selected row. Each row of the grid can have different values in the drop down and I need to pass the value into the AjaxGetEmps method. I'm using ASP.NET MVC with the Razor view engine.

推荐答案

您必须通过通过数据方法的 EMPID 参数,而不是直接给出这样的参数:

You have to pass the Empid parameter via the Data method instead of giving directly the parameter like this :

@(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函数应该像这样实现:

and the javascript function should be implemented like this :

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(行) GET该数据与该行相关的。所以在这里 EMPID 应该是你的模型类的ID。
还要注意的是,如果你有标志 GridSelectionMode ,你将不得不循环扔 grid.select()阵列...

Here grid.select() returns the selected line in your grid and grid.dataItem(row) get the data associated with this row. So here Empid should be the id of your model class. Note also that if you have the flag GridSelectionMode to Multiple you will have to loop threw the grid.select() array...

这篇关于Kendoui的DropDownList与Ajax和放慢参数格(ASP.NET MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆