繁体   English   中英

jQuery multiselect在POST之后返回一个选择

[英]Jquery multiselect comes back with one selected after POST

我有一个Jquery multiselect控件

$(function () {
    $(".multiselect").multiselect().multiselectfilter({
        filter: function (event, matches) {
            if (matches.length != null && !matches.length) {
                // do something
            }
        }
    });
});

并将其链接到DropDownListFor

@Html.DropDownListFor(x => x.ID, new MultiSelectList(Model.Employees, "Id", "Name"), "Please Select", new {multiple = "multiple", @class = "multiselect"})  

当我按下按钮发布时,强类型模型会发送列表中选择的任何人。 好。 但是,发布后,它仅显示DropDownListFor的第一个选定项目,而不显示其他项目。 当发布带有所选ID的信息时,我确实将模型发回

// Model.ID which is a `int[]` is bounded to the `DropDownListFor` above has multiple values inside it. 
return View("View" Model)

我是否需要对Jqueryrazor侧做一些操作以在回发中显示其他选定项?

谢谢

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"}) 

哇,好,我发现了问题。

我不确定它是否是.NET错误或我需要在代码中进行更改的内容,但是

@Html.DropDownListFor(x => x.ID, new MultiSelectList(Model.Employees, "Id", "Name"), "Please Select", new {multiple = "multiple", @class = "multiselect"}) 

@Html.ListBoxFor(x => x.ID, new MultiSelectList(Model.Employees, "Id", "Name"), "Please Select", new {multiple = "multiple", @class = "multiselect"}) 

只是神奇地工作。

现在,在寻找解决方案的过程中,我再也没有看到一个帖子说“ DropDownListFor不能与multiSelectList或它们上的任何行一起工作,但是我很乐意有人解释它做错了什么吗?

但是,这样可以节省一些人寻找解决方案的时间。

感谢所有帮助的人:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM