我无法在 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/