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编辑器模板将无法正确默认为该值.