Skip to content Skip to sidebar Skip to footer

Strange Problem With ASP.NET MVC DropDownFor

Hi, I have the following in my view :
'> <%: Html.DropDownListFor(mod

Solution 1:

Your problem here is ModelState. You POST to your Action and return the same view. The second time the view is rendered it will look at the ModelState and use those values to fill your controls. This is used for when validation fails:

if(!ModelState.IsValid)
    return View(model);

Is this scenario the values that the user entered are again selected. Your case is simple to fix, just use:

ModelState.Clear();

before you return the View.


Post a Comment for "Strange Problem With ASP.NET MVC DropDownFor"