0
這裏是我的模型類ASP.NET MVC多選列表框沒有選擇多個值
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文本框正在呈現正確,但它只選擇一個值,它不選擇多個值。
無法確定問題的實際位置!任何幫助請!
你是什麼意思_selecting only value_? –
它僅選擇一個值。如果我在選擇一個值後嘗試選擇另一個值,則以前的選擇正在丟失。 – TanvirArjel
不相關,但建議您只使用'ViewBag.AttachmentList = dbContext.AttachmentAndFolders.Where(...)。Select(x => new SelectListItem {Value = x.AttchmentFolderId,Text = x.Name});'' @ Html.ListBoxFor(m => m.AttachmentId,(IEnumerable)ViewBag.AttachmentList)' –