dotNet Core Clear Dropdownlist selections

203 views Asked by At

I have a Razor View with a dropdown list:

<select size="7" style=" width: 275px; color:#967a42;" class="table-dark" asp-for="OptionsToAdd" asp-items="@(new SelectList(@ViewBag.OptionsDD, "Value", "Text"))" multiple></select>

When I submit the page, the controller resets the list and selected items, yet when the view is displayed, the same items are still selected from before the POST. How can I clear this?

This only happens in the view. The model that is passed in has all items in the Viewbag.OptionsDD with selected=false.

1

There are 1 answers

0
Yinqiu On BEST ANSWER

You can try to change you code like below:

  <select size="7" style=" width: 275px; color:#967a42;" class="table-dark" name="OptionsToAdd"  asp-items="@(new SelectList(@ViewBag.OptionsDD, "Value", "Text"))" multiple> 
    </select>