剑道:网格中的组合框 - 将选定组合框的附加数据发送到组合框 Read() [英] Kendo : ComboBox in a grid - Sending additional data of selected combobox to combobox Read()

查看:19
本文介绍了剑道:网格中的组合框 - 将选定组合框的附加数据发送到组合框 Read()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET MVC5

ASP.NET MVC5

我在网格中有一个组合框(内联编辑):

I have a combobox in a grid (InLine Edit):

columns.Bound(x=>x.AccountID).EditorTemplateName("MyTemplate")

MyTemplate 在/Shared 中的位置

Where MyTemplate is in /Shared

有数百万个帐户.

当我尝试编辑网格中的组合框并选择一个新值时,会出现帐户 ID,而不是名称.这是因为当然帐户名称不会立即出现,所以在 ComboBox.Datasource 的 Read().Data() 中我需要发送附加数据;帐户 ID.

When I try to edit the combo box in a grid and choose a new value, the ID of the Account, not the name, appears. This is because of course the name of the account is not immediately present so in the Read().Data() of the ComboBox.Datasource I need to send additional data; the AccountID.

我的 ComboBox 模板如下所示:

My ComboBox Template looks like this:

.DataSource(source=>
   source.Read(read =>
      read.Action("ReadAccounts".....)
         .Data("HERE IS WHERE I NEED TO SEND THE ACCOUNT ID AS EXTRA DATA 
             WHEN THIS CBO TEMPLATE IS IN A GRID")

谢谢

推荐答案

这里是在~/Views/Shared/EditorTemplates/ComboBoxTemplate

@(Html.Kendo().ComboBox()
          .Name("AcctName")//must match Field Name that is being edited
          .HtmlAttributes(new { style = "width:250px" })
          .DataTextField("AcctName")
          .DataValueField("AcctCd")
          .Filter(FilterType.StartsWith)
          .AutoBind(true)
          .MinLength(3)
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("GetCombo", "GridPost").Data("OnAdditionalData");
              })
              .ServerFiltering(true);
          })          
)

这是视图和控制器操作

columns.Bound(x => x.AcctName).Title("Acct Name").EditorTemplateName("ComboBoxTemplate");

 function OnAdditionalData() {          

            var entityGrid = $("#ProposalGridX").data("kendoGrid");
            var selected = entityGrid.dataItem(entityGrid.select());
            //if the id is off the Grid Row and not the ComboBox
            //select the row and pull the fields
            //selected.PropertyName

            return {
                text : $("#AcctName").data("kendoComboBox").text(),
                 val : $("#AcctName").data("kendoComboBox").value()
            };
        }

   public JsonResult GetCombo(string text, string val)
   {
         List<PortfolioViewModel> model = new AUMBusiness().GetAum(DateTime.Now);

           if (!string.IsNullOrEmpty(text))
            {
               model = model.Where(x => x.AcctName.StartsWith(text)).ToList();
            }

         return Json(model, JsonRequestBehavior.AllowGet);
    }

与任何 Ajax 调用一样,在代码中放置断点可能会阻止小部件按预期执行.例如.在单击要编辑的字段时使用 incell 编辑,如果在 GetCombo 中放置断点,ComboBox 编辑器模板将不会正确默认为该值.

Like with any Ajax calls, placing break points in the code might prevent the widget from performing as intended. For ex. using incell editing while clicking the Field to edit, if you place a breakpoint in GetCombo the ComboBox editor template will not default correctly to that value.

这篇关于剑道:网格中的组合框 - 将选定组合框的附加数据发送到组合框 Read()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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