Here is my Model Class
public class OperationStudyInputViewModel
{
public IEnumerable<string> AttachmentId { get; set; }
}
Here is my Controller Method:
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");
}
Here is View :
<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 is rendering properly but it selecting only one value, its not selecting multiple value.
Cannot identify where the problem actually is!! Any Help Please!!
ViewBag.AttachmentList = dbContext.AttachmentAndFolders.Where(...).Select(x => new SelectListItem{ Value = x.AttchmentFolderId, Text = x.Name });and@Html.ListBoxFor(m => m.AttachmentId,(IEnumerable<SelectListItem>)ViewBag.AttachmentList)<select multiple="multiple" ... >element. Do you have any javascript that is altering the behavior?