Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


MVC 4 Html.ListBoxFor Model MultiSelectList IEnumerable Error?

Posted on 2014-01-13
Medium Priority
Last Modified: 2014-01-19
I have successfully using the Html.ListBox with a ViewData like so:

ViewData["GroupsList"] = new MultiSelectList(myGroups.GetAllGroups(), "GroupID", "GroupName");

@Html.ListBox("lbxGroups", (MultiSelectList)ViewData["GroupsList"], new { SelectionMode = "Single" })

Now I want to use the Model and having issues doing so.

I received this error when using Model.UserGroupList:

"The parameter 'expression' must evaluate to an IEnumerable when multiple selection is allowed."

Note: the Action returns the correct data.

public ActionResult Index()
       ManagerViewModel viewModel = new ManagerViewModel()
                UserGroupsList = new MultiSelectList(myGroups.GetAllGroups(), "GroupID", "GroupName")
            return View(viewModel);

@model ProjectUI.ManagerViewModel
@Html.ListBoxFor(model => model.GroupId, new MultiSelectList(Model.UserGroupsList, "Value", "Text"), new { SelectionMode = "Single" }))

public class ManagerViewModel
        public int GroupId { get; set; }
        public MultiSelectList UserGroupsList { get; set; }
Question by:WorknHardr
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 16

Accepted Solution

Imran Javed Zia earned 2000 total points
ID: 39778720

If you have single selection, then technically you may use dropdown. Please try following:

@Html.ListBoxFor(model => model.GroupId,
                new SelectList(Model.UserGroupsList, "Value", "Text"))

for more information, please refer to following:


Author Comment

ID: 39779504
Same error:
"The parameter 'expression' must evaluate to an IEnumerable when multiple selection is allowed."

Until.... I change the Action to SelectList from MultiSelectList like so:

     ManagerViewModel viewModel = new ManagerViewModel()
                UserGroupsList = new SelectList(myGroups.GetAllGroups(), "GroupID", "GroupName")

Q. Why do I find code snippets elsewhere using the MultiSelectList?

Author Comment

ID: 39779733
Just tried this example and get the same working result as your suggestion, without using a SelectList in the view.

View model:
public class MyViewModel
    public int[] SelectedIds { get; set; }
    public IEnumerable<SelectListItem> Items { get; set; }

public ActionResult Index()
    var model = new MyViewModel
        // fetch the items from some data source
        Items = Enumerable.Select(x => new SelectListItem
            Value = x.Id,
            Text = "item " + x.Id
    return View(model);

@model MyViewModel
@Html.ListBoxFor(x => x.SelectedIds, Model.Items)

Author Closing Comment

ID: 39792647

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question