Kendo ASP.NET MVC-将下拉添加到网格
因此,我一直在遵循一些教程以及其他一些示例,因此有关如何将下拉列表添加到我的Kendo Grid中的帖子,尽管我在使其正常工作方面几乎没有成功。我的网格如下:
@(Html.Kendo().Grid<SampleUserModel>()
.Name("SearchResults")
.Deferred()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read
.Action("Search", "Users")
)
.PageSize(ViewConstants.PageSizeGridDefault)
)
.Columns(columns =>
{
columns.Bound(e => e.Name).Title("Name");
columns.Bound(c => c.MappedValue).EditorTemplateName("_MappingValueDropDown")
.ClientTemplate("#:MappedValue#");
})
.Sortable(sortable => sortable.AllowUnsort(true).SortMode(GridSortMode.MultipleColumn))
.Pageable(pageable => pageable.Refresh(true).PageSizes(true).PageSizes(ViewConstants.PageSizes).ButtonCount(5))
.Events(events => events.DataBound("sampleController.onDataBoundGrid"))
.AutoBind(false)
.HtmlAttributes(new { id = "userKendoGrid", style = "display:none;", data_form = "userMappingForm" }))
我的下拉列表,我将其放置在视图/共享/editortemplates/_mappingValueDropdown.cshtml中:
@using Kendo.Mvc.UI
@model string
@(Html.Kendo().DropDownListFor(o => o)
.DataSource(source =>
{
source.Read(read =>
{
read.Route("GetUserMappingCodes");
});
})
.OptionLabel("[Select]")
.DataValueField("ID")
.DataTextField("DisplayText")
.Name("MappingDropdown"))
但是,下拉列表从未出现在网格中。直到用户填充搜索过滤器并单击搜索按钮之前,网格中的数据才填充,所以我不确定这是否是问题的一部分?我找不到其他人在做什么,所以我对自己做错了什么感到困惑。在控制器操作中,我有一个断点,即下拉呼叫,但它从未被击中,感觉模板甚至没有被渲染。
So I have been following a few tutorials as well as some examples on other SO posts on how to add a drop down list to my Kendo grid, though I've been having little success in getting it to work. My grid is as follows:
@(Html.Kendo().Grid<SampleUserModel>()
.Name("SearchResults")
.Deferred()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read
.Action("Search", "Users")
)
.PageSize(ViewConstants.PageSizeGridDefault)
)
.Columns(columns =>
{
columns.Bound(e => e.Name).Title("Name");
columns.Bound(c => c.MappedValue).EditorTemplateName("_MappingValueDropDown")
.ClientTemplate("#:MappedValue#");
})
.Sortable(sortable => sortable.AllowUnsort(true).SortMode(GridSortMode.MultipleColumn))
.Pageable(pageable => pageable.Refresh(true).PageSizes(true).PageSizes(ViewConstants.PageSizes).ButtonCount(5))
.Events(events => events.DataBound("sampleController.onDataBoundGrid"))
.AutoBind(false)
.HtmlAttributes(new { id = "userKendoGrid", style = "display:none;", data_form = "userMappingForm" }))
And my drop down list, which I placed in Views/Shared/EditorTemplates/_MappingValueDropDown.cshtml:
@using Kendo.Mvc.UI
@model string
@(Html.Kendo().DropDownListFor(o => o)
.DataSource(source =>
{
source.Read(read =>
{
read.Route("GetUserMappingCodes");
});
})
.OptionLabel("[Select]")
.DataValueField("ID")
.DataTextField("DisplayText")
.Name("MappingDropdown"))
However, the dropdown never appears in the grid. The data in the grid is not populated until the user populates search filters and clicks a search button, so I'm not sure if this is part of the issue? I can't find anything different in what other people are doing so I'm baffled as to what I'm doing wrong. I have a breakpoint in the controller action the dropdown calls but it is never hit, it feels like the template isn't even being rendered.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了原因,我的网格缺少可编辑和模型配置。我更新了电网以添加以下内容,现在下拉列表工作。使网格可编辑:
以及在数据源中添加模型调用:
I figured out the cause, my grid was missing Editable and Model configurations. I updated my grid to add the following and the dropdowns work now. Making the grid editable:
And the adding the model call in DataSource: