How to select items through code in listboxfor

161 views Asked by At

I have an Entity Framework/ASP.NET MVC web page.

My .cshtml has this code to populate the list:

 <li style="float:left;width:20%;list-style-type: none;">
        <b>List of Users </b><br />
        @Html.ListBoxFor(x => x.selectedUsers, Model.ListofUsers, new { style = "width:200px" })
        <br />

 </li>

How do I programmatically select or unselect all the items from this list?

I assume if I create the SelectListItem object with the property Selected = true; then the item may be selected.

Let us say if I have a button that has to toggle between selection and unselection - the button can possibly update the list of item objects. But how will it refresh the page?

0

There are 0 answers