ASP.NET MVC DropDownList Validation
Posted
by Andrew Florko
on Stack Overflow
See other posts from Stack Overflow
or by Andrew Florko
Published on 2010-05-16T15:53:29Z
Indexed on
2010/05/16
16:00 UTC
Read the original article
Hit count: 800
Hello everybody,
I have
[DisplayName("Country")]
public List<SelectListItem> Countries { get; set; }
property in Model class for DropDownList.
When I try to check if the ModelState.IsValid on form postback it's always false & error for Countries tells "Can't convert [value] to SelectListItem" or some of a kind.
I figured out there is no straight-forward mapping for drop down selected value (looks like I'll have to read value from Form value collection), but how can I ignore binding and validation for List property? I just want to make ModelState.IsValid attribute to be true if all the other fields are populated properly.
Thank you in advance
© Stack Overflow or respective owner