客户端详细信息模板中的DropDown列表 - Kendo网格

时间:2016-04-05 13:54:02

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

我正在尝试在客户端模板中添加下拉列表,但不知何故不能,有人可以帮我这个吗?

 columns.Bound(o => o.ImportFunctionText).ClientTemplate("# if (ImportFunction == 0) { # Account # } else if (ImportFunction == 1) { # Row # } #")
                      .EditorTemplateName("DropDownList")
                      .EditorViewData(new
                      {
                          Id = "ImportFunction",
                          Data = ViewBag.dropDownList,
                          FieldName = "value:ImportFunction"
                      })
                      .Width(210)
                      .Title("Function");

感谢。

1 个答案:

答案 0 :(得分:0)

为了使用编辑器模板,您必须将编辑器模板存储在〜/ Views / Shared / EditorTemplates / tmp_dropdown_attribute.cshtml文件夹中作为局部视图。

根据telerik asp net mvc docs,你的模板应如下所示:

@(Html.Kendo().DropDownList()
.Name("Employee") // Name of the widget should be the same as the name of the property
.DataValueField("EmployeeID") // The value of the dropdown is taken from the EmployeeID property
.DataTextField("EmployeeName") // The text of the items is taken from the EmployeeName property
.BindTo((System.Collections.IEnumerable)ViewData["employees"]) // A list of all employees which is populated in the controller

并且您的控制器应该在控制器方法中绑定viewdata容器,该方法生成如下视图:

public ActionResult Index()
{
ViewData["employees"] = new NorthwindDataContext()
             .Employees
             .Select(e => new Employee
             {
                  EmployeeID = e.EmployeeID,
                  EmployeeName = e.FirstName + " " + e.LastName
             })
             .OrderBy(e => e.EmployeeName);

return View();
}

如需进一步阅读,请参阅可在此处找到的文档: http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/templating/editor-templates