Kendo MVC Grid - 使用内联编辑进行下拉

时间:2016-05-17 14:33:34

标签: kendo-grid kendo-asp.net-mvc inline-editing

我已经搜遍了所有的解决方案并尝试了许多建议(只是说如果你认为我太懒了) 我是一个剑道菜鸟,所以不确定我错过了什么?

正如标题所说,我有一个项目网格,想要内联编辑它们。一切正常,但似乎我的编辑器模板被忽略,并且在编辑模式下显示2个输入(因为必须选择的子对象是具有Id和Name属性的复杂对象)

ps:抱歉格式化。好像我的浏览器没有显示这个Windows工具栏? 剑道MVC网格

Html.Kendo().Grid<MyViewModel>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(o => o.Id).Hidden(true);
        columns.Bound(o => o.Product).EditorTemplateName("ProductsListTemplate");
        ...other columns
        columns.Command(command =>
        {
            command.Edit();
            command.Destroy();
        }).Width(180);
    })
    .AutoBind(true)
    .ToolBar(toolbar => toolbar.Create())
         .Editable(editable => editable.Mode(GridEditMode.InLine).Enabled(true))
    .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
    .Resizable(resize => resize.Columns(true))
    .Selectable(sel => sel.Mode(GridSelectionMode.Single)
    .Enabled(true))
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Events(events => events.Error("error_handler"))
        .Model(model =>
        {
            model.Id(c => c.Id);
            model.Field(c => c.Product).Editable(true);
            ...other fields...
        })
        .Create(update => update.Action("Create", "MyController"))
        .Read(read => read.Action("Read", "MyController"))
        .Update(update => update.Action("Edit", "MyController"))
        .Destroy(update => update.Action("Delete", "MyController"))
    ))

ProductsListTemplate.cshtml(在Shared / EditorTemplates中,产品选项在viewdata中显示为IEnumerable)

@(Html.Kendo().DropDownList()
      .Name("MyChildViewModel") 
      .DataValueField("Id")
      .DataTextField("Name")
      .BindTo((IEnumerable) ViewData["ProductOptions"])
      )

MyViewModel     公共类MyViewModel     {         public int Id {get;组; }

    [Display(Name = "Product")]
    [UIHint("ProductsListTemplate")]
    public MyChildViewModelProduct { get; set; }

......其他属性

public class MyChildViewModel
{
    public string Id { get; set; }
    public string Name { get; set; }
}

0 个答案:

没有答案
相关问题