views:

189

answers:

1

I currently have no validation for my drop down list, but nevertheless, I get a validation error in my ModelState when no value is selected.

Is there any automated validation when you specify a default option?

It isn't part of the Model, so it definitely isn't a missed attribute!

<%= Html.DropDownList("CategoryId", 
    (IEnumerable<SelectListItem>)ViewData["categories"], "-- Select --")%>
A: 

I didn't get any suggestions on this one - but if you've arrived here looking for an answer, this is how I solved my issue:

Instead of passing in the default value to the DropDownList, I initialize the category list with a default instead (i.e. you put { "[YourDefaultValue]", "-- Select --" } as the first SelectListItem).

<%= Html.DropDownList("CategoryId", 
    (IEnumerable<SelectListItem>)ViewData["categories"])%>
Sohnee