How to remove selected property from ListBoxFor

767 Views Asked by At

I am using Html.ListBoxFor to populate a list of entries from MVC Model

@Html.ListBoxFor(m => m.DetailsBook, new SelectList(Model.DetailsBook), new { @id = "BookList" })

Now everything works expect that the list items by default selected. Is there anyway I can remove that and just populate these values in list box?

1

There are 1 best solutions below

0
On BEST ANSWER

This happens because you're using DetailsBook as both the list and the main expression.

So what you need to do is create another property, and use that for 'selected values'. e.g.

Model:

public string Details { get; set; }
public List<string> DetailsBook { get; set; }

View:

@Html.ListBoxFor(m => m.Details, new SelectList(Model.DetailsBook), new { @id = "BookList" })