asp.net – 剑道:网格中的ComboBox – 将选定组合框的其他数据发送到组合框Read()

ASP.NET MVC5

我在网格中有一个组合框(InLine Edit):

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

MyTemplate在/共享的地方

有数百万的帐户.

当我尝试编辑网格中的组合框并选择新值时,将显示帐户的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")

谢谢

解决方法

这是在〜/ 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调用一样,在代码中放置断点可能会阻止窗口小部件按预期执行.对于前者单击要编辑的字段时使用单元格编辑,如果在GetCombo中放置断点,则ComboBox编辑器模板将无法正确认为该值.

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...