[英]Jquery multiselect comes back with one selected after POST
I have a Jquery multiselect
control 我有一个
Jquery multiselect
控件
$(function () {
$(".multiselect").multiselect().multiselectfilter({
filter: function (event, matches) {
if (matches.length != null && !matches.length) {
// do something
}
}
});
});
And this is linked to a DropDownListFor
并将其链接到
DropDownListFor
@Html.DropDownListFor(x => x.ID, new MultiSelectList(Model.Employees, "Id", "Name"), "Please Select", new {multiple = "multiple", @class = "multiselect"})
When I press a button to post, the strongly typed model does send whoever has been selected in the list. 当我按下按钮发布时,强类型模型会发送列表中选择的任何人。 Good.
好。 However, after the post, it only displays the first selected item in the
DropDownListFor
and not the others. 但是,发布后,它仅显示
DropDownListFor
的第一个选定项目,而不显示其他项目。 I do send the model back when the post has happened with the IDs that are selected 当发布带有所选ID的信息时,我确实将模型发回
// Model.ID which is a `int[]` is bounded to the `DropDownListFor` above has multiple values inside it.
return View("View" Model)
Do I need to do something to the Jquery
or the razor
side to display the other selected items on postback? 我是否需要对
Jquery
或razor
侧做一些操作以在回发中显示其他选定项?
Thanks 谢谢
In msdn present a constructor which receives selectedValues. 在msdn中,提供一个接收selectedValues的构造函数。
public MultiSelectList(
IEnumerable items,
string dataValueField,
string dataTextField,
IEnumerable selectedValues
)
@Html.DropDownListFor(x => x.ID, new MultiSelectList(Model.Employees, "Id", "Name", Model.ToList()), "Please Select", new {multiple = "multiple", @class = "multiselect"})
Wow, OK, I found the problem. 哇,好,我发现了问题。
I am not sure if its a .NET bug or something I need to change in my code, but changing 我不确定它是否是.NET错误或我需要在代码中进行更改的内容,但是
@Html.DropDownListFor(x => x.ID, new MultiSelectList(Model.Employees, "Id", "Name"), "Please Select", new {multiple = "multiple", @class = "multiselect"})
To 至
@Html.ListBoxFor(x => x.ID, new MultiSelectList(Model.Employees, "Id", "Name"), "Please Select", new {multiple = "multiple", @class = "multiselect"})
Just magically works. 只是神奇地工作。
Now, In my searching for a solution, I never saw one post to say "DropDownListFor's do not work with multiSelectList or anything on them lines but I wou;ld be happy for someone to explain if its something I done wrong? 现在,在寻找解决方案的过程中,我再也没有看到一个帖子说“ DropDownListFor不能与multiSelectList或它们上的任何行一起工作,但是我很乐意有人解释它做错了什么吗?
However, this may save someone searching for hours for the solution. 但是,这样可以节省一些人寻找解决方案的时间。
Thanks to everyone who helped :) 感谢所有帮助的人:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.