0

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!!

6
  • What do you mean selecting only value? Commented Feb 19, 2017 at 11:58
  • Its selecting only one value..If I try to select another value after selecting one, the previous selection is being lost. Commented Feb 19, 2017 at 12:00
  • Not related, but suggest you just use 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) Commented Feb 19, 2017 at 12:02
  • What your claiming is not possible - your code generates a <select multiple="multiple" ... > element. Do you have any javascript that is altering the behavior? Commented Feb 19, 2017 at 12:04
  • May be Not!! By the way should I hold down the control button to select multiple or just clicking serially on individual...?? Commented Feb 19, 2017 at 12:20

1 Answer 1

1

Multiselect List Boxes require that you hold down Ctrl to select multiple items.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.