Tech Off Post

Single Post Permalink

View Thread: ASP.NET MVC MultiSelect issue
  • User profile image
    Maddus Mattus

    ZippyV said:

    The code in the View:

    <%: Html.ListBoxFor(Function(m) m.NewsItem.NewsCategories, Model.Categories)%>

    I have had my share of headache's with the HTML.ListBoxFor

     

    One of the gotacha's is; don't put any ViewData[] or other stuff on your form that interferes with the name, ID's ect.

     

    Here's how I use em, that I found works:

     

    The SalesOpsManagers is just an IList<string>

     

    <%

    = Html.ListBoxFor(model => model.SalesOpsManagers, (IEnumerable<SelectListItem>)ViewData["TerritorySalesOpsManagers"], new { style = "width:250px;" })%>

     

    And the viewdata is in the form of a selectlistitem, doesnt need to be multiselectlist item

     

    hope this helps you