【发布时间】:2016-06-22 11:52:25
【问题描述】:
我需要实现简单的下拉列表来选择预定义的文化。
我的网格:
@(Html.Kendo().Grid<NewLibrary.ViewModels.BookViewModel>()
.Name("booksGrid")
.Columns(column =>
{
column.Bound(m => m.Name);
column.Bound(m => m.Culture).EditorTemplateName("CultureSelectorTemplate");
})
.ToolBar(toolBar =>
{
toolBar.Create();
toolBar.Save();
})
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(10)
)
.HtmlAttributes(new { style = "border-style: double; border-width: 5px" })
.Editable(e => e.Mode(GridEditMode.InCell))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(false)
.Model(m =>
{
m.Id(f => f.BookId);
m.Field(f => f.Name);
m.Field(f => f.Culture);
})
.Create(create => create.Action("CreateBooks", "Books"))
.Read(read => read.Action("ReadBooks", "Books"))
.Update(update => update.Action("UpdateBooks", "Books"))
.Destroy(destroy => destroy.Action("DeleteBooks", "Books"))
)
)
我在 /Shared/EditorTemplates 中的编辑器模板:
@(Html.Kendo().DropDownList()
.Name("Culture")
.DataTextField("Text")
.DataValueField("Value")
.BindTo(new List<SelectListItem>()
{
new SelectListItem()
{
Text = "English",
Value = "en"
},
new SelectListItem()
{
Text = "Spanish",
Value = "es"
},
new SelectListItem()
{
Text = "French",
Value = "fr"
}
})
)
我的视图模型:
public class BookViewModel
{
public string BookId { get; set; }
public string Name { get; set; }
public string Culture { get; set; }
}
问题是,我无法将下拉列表中的值绑定到模型,当我从列表中选择它们,然后要编辑另一本书时,列表中的值消失了。
这个实现有什么问题,我怎样才能做到正确,同时谷歌搜索几十个相同的答案,什么也没给我。
那么,通过 Asp.Net Core 在 Kendo Grid 中实现 DropDownList 的正确方法是什么?
【问题讨论】:
标签: c# kendo-grid asp.net-core-mvc kendo-asp.net-mvc