【问题标题】:Kendo : ComboBox in a grid - Sending additional data of selected combobox to combobox Read()剑道:网格中的组合框 - 将选定组合框的附加数据发送到组合框 Read()
【发布时间】:2014-10-14 16:52:42
【问题描述】:

ASP.NET MVC5

我在 grid 中有一个 combobox(内联编辑):

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

MyTemplate 在 /Shared 中的位置

有数百万个帐户。

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

我的 ComboBox 模板如下所示:

.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")

谢谢

【问题讨论】:

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


    【解决方案1】:

    这是~/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 中放置断点,则组合框编辑器模板将无法正确默认为该值。

    【讨论】:

    • 问题是如何将选定的组合框的值和测试发送到.Data()。当他们在网格中时,我如何找到他们?
    • 看看我的编辑,它基本上是使用内联编辑器模板中的下拉菜单复制粘贴的代码,并捕获要捕获的更改事件,ddlId 和 rowId。您应该能够使其适用于您的场景
    • 不知道有没有帮助telerik.com/forums/…
    • @Bahai,我修改了答案并发布了所有相关代码。进入编辑模式时,组合框编辑器将被填充,并允许您传递任何字段/值以及组合框的搜索文本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多