asp.net-mvc - Kendo UI 多选发布数据未到来,列表计数 = 0

标签 asp.net-mvc

我无法在 Controller 中获取 Kendo UI Multiselect 的值。它给我的列表长度为 0。MultiSelect 为:

@(Html.Kendo().MultiSelectFor(model => model.Technicians)
                            .Name("Technicians")
                            .Placeholder("Select Technician(s)")
                            .DataTextField("Name")
                            .DataValueField("ID")
                            .Filter(FilterType.Contains)
                            .AutoBind(true)
                            .DataSource(source =>
                            {
                                source.Read(read =>
                                {
                                    read.Action("GetTechnicians", "Project");
                                })
                                .ServerFiltering(false);
                            })
                            .BindTo(Model.Technicians)          
                        )

技术人员是:public List Technicians{get;设置;在模型中

最佳答案

我也遇到了这个问题。

我们最终创建了一个 IEnumerable<int> View 模型中的 ID 来存储该值。

所以,在我们的例子中

public IEnumerable<PersonLookupViewModel> TaggedPersons { get; set; } (这是我真正想要的具有 ID 的人员列表 - 包含 first/last/id)

public IEnumerable<int> PeopleToTag { get; set; } (这是 View 模型的 IEnumerable Int,仅用于将整数发布到 Controller )

我的观点是这样的:

<div class="editor-field">       
  @Html.LabelFor(model => model.taggedPersons)
  @Html.ListBoxFor(model => model.PeopleToTag, 
     new SelectList(Model.CommitteeMembers, "PersonId", "FullName"))                  
</div>

然后 JS 连线

$("#PeopleToTag").kendoMultiSelect({ "dataTextField": "FullName", "dataValueField": "PersonId", "placeholder": "Tag or Untag Persons to Action Item" });

所以将它切换到 ListBoxFor(model => model.PeopleToTag) 这是我在 View 模型中的 Ienumerable 字段,只是为了能够在 Controller 中获取数据。然后,我使用 automapper 创建了我实际需要的 Person 模型。

我不确定这是否是最佳方式,但它对我们有用。

关于asp.net-mvc - Kendo UI 多选发布数据未到来,列表计数 = 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22945004/

相关文章:

asp.net - 为什么要在Windows Server上的.NET上的.NET Core上运行ASP.NET Core

c# - 如何在不使用mysql中的函数的情况下使每个单词的首字母大写?

c# - 如何在存储库模式中执行异步等待?

asp.net-mvc - 部署 azure 应用程序

c# - MVC RouteConfig "CatchAll"{*url} 不工作

asp.net-mvc - Azure 身份验证与 OAuth 身份验证结合使用

c# - Styles.Render 在 View 中

jquery - 使用T4MVC,如何在HTML表单上设置action属性

c# - Summernote 和 MVC c# 中的表单提交

asp.net-mvc - 在ASP.NET MVC中,如何将xml文档返回到 View