Kendo ASP.NET MVC-将下拉添加到网格

发布于 2025-01-31 17:48:55 字数 1540 浏览 4 评论 0原文

因此,我一直在遵循一些教程以及其他一些示例,因此有关如何将下拉列表添加到我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巨坚强 2025-02-07 17:48:55

我发现了原因,我的网格缺少可编辑和模型配置。我更新了电网以添加以下内容,现在下拉列表工作。使网格可编辑:

    .Editable(editabe => editabe.Mode(GridEditMode.InCell))

以及在数据源中添加模型调用:

.Model(model =>
    {
        model.Id(o => o.ID);
        model.Field(d => d.Name).Editable(false);
        model.Field(d => d.MappedValue);
    }

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:

    .Editable(editabe => editabe.Mode(GridEditMode.InCell))

And the adding the model call in DataSource:

.Model(model =>
    {
        model.Id(o => o.ID);
        model.Field(d => d.Name).Editable(false);
        model.Field(d => d.MappedValue);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文