【发布时间】:2014-02-05 10:55:57
【问题描述】:
如果没有任何更改,我的 KendoUI MultiSelect 仅返回第一个选定的值。
当我加载 Viewpage 时,MultiSelect 会正确填充数据和多项选择。当我现在继续保存数据而不进行任何更改(!)时,传输到我的控制器的模型(大多数情况下,无法识别模式)仅包含相应字段中的第一个选定项目。如果我添加新选择,则只有先前选择的第一个项目与新选择的项目一起返回。
如果我使用 .AutoBind(false) 然后单击一次进入该字段,然后再次单击外部而没有取消/选择任何内容,则传输到我的控制器的模型包含保存时的全部内容。
在同一个 ViewPage 上有多个 MultiSelect(在不同的数据上),在一个 MultiSelect 上使用 .AutoBind(false) 就足够了(随后像上面一样单击),这样所有 MultiSelect 都会突然返回全范围的选定值.
任何人都可以向我解释这种奇怪的行为,甚至可以修复吗?
View 中的两个不同实现,它们都表现出相同的行为(GetDepotList() 返回相似的内容给 ViewData["DepotList"]):
@model List<LoadingUnitViewModel>
[...]
//Version 1
@(Html.Kendo().MultiSelectFor(m => m[i].FK_Depots)
.Name("[" + i.ToString() + "]." + "FK_Depots")
.Placeholder(Localize((string)ViewData["ControllerName"], "ChooseDepot"))
.DataValueField("Value")
.Value(Model[i].FK_Depots)
.DataTextField("Text")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetDepotList", (string)ViewData["ControllerName"]);
})
.ServerFiltering(true);
})
.HtmlAttributes(new { id = "_" + i + "__FK_Depots"})
)
//Version 2
@(Html.Kendo().MultiSelectFor(m => m[i].FK_Depots)
.Name("["+i.ToString()+"]."+"FK_Depots")
.Placeholder(Localize((string)ViewData["ControllerName"], "ChooseDepot"))
.BindTo(new MultiSelectList((System.Collections.IEnumerable)ViewData["DepotList"], "Id", "Name", Model[i].FK_Depots))
)
编辑: 根据要求:LoadingUnitViewModel 的相关部分:
public class LoadingUnitViewModel
{
[Editable(false)]
[Display(Name = "Id")]
public int Id { get; set; }
[Required]
[Display(Name = "Name")]
public string Name { get; set; }
[Display(Name = "FK_Depots")]
public List<string> FK_Depots { get; set; }
}
【问题讨论】:
-
你的
LoadingUnitViewModel是什么样的? -
已编辑到原帖中。
-
您使用 AJAX 绑定是否有原因?我有一个想法,但不需要那样绑定。
-
我总是对想法持开放态度。这个问题已经花费了我足够多的时间......
-
我在某处有一些代码。我看看能不能找到。
标签: asp.net-mvc-4 kendo-ui kendo-asp.net-mvc