ASP.NET MVC Multiselect ListBox未选择多个值

时间:2017-02-19 11:52:44

标签: c# asp.net asp.net-mvc razor

这是我的模型类

public class OperationStudyInputViewModel
{
   public IEnumerable<string> AttachmentId { get; set; }
}

这是我的控制器方法:

public ActionResult OperationStudyInput()
{
    var attachmentList = _dbContext.AttachmentAndFolders
        .Where(x => x.IsAttachementOrFolder == "Attachment")
        .Select(x => new 
        {
            x.AttchmentFolderId,
            x.Name
        }).ToList();
    ViewBag.AttachmentList = new MultiSelectList(attachmentList, "AttchmentFolderId", "Name");
}

以下是视图:

<div class="input-group input-group-lg col-md-6">
    @Html.LabelFor(model => model.AttachmentId, htmlAttributes: new { @class = "input-group-addon" })
    @Html.ListBoxFor(model => model.AttachmentId,(MultiSelectList)ViewBag.AttachmentList)
</div>

MultiSelet Textbox正确渲染,但它只选择一个值,而不是选择多个值。

无法确定问题的实际位置!!任何帮助请!!

1 个答案:

答案 0 :(得分:1)

多选列表框要求您按住Ctrl键选择多个项目。