加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 剑道:网格中的ComboBox – 将选定组合框的其他数据

发布时间:2020-12-15 22:26:11 所属栏目:asp.Net 来源:网络整理
导读:ASP.NET MVC5 我在网格中有一个组合框(InLine Edit): columns.Bound(x=x.AccountID).EditorTemplateName("MyTemplate") MyTemplate在/共享的地方 有数百万的帐户. 当我尝试编辑网格中的组合框并选择新值时,将显示帐户的ID,而不是名称.这是因为当然帐户的名
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编辑器模板将无法正确默认为该值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读