I am trying to understand the best way of implementing a DropDownList
in ASP.NET MVC 2 using the DropDownListFor
helper. This is a multi-part question.
First, what is the best way to pass the list data to the view?
- Pass the list in your model with a
SelectList
property that contains the data - Pass the list in via
ViewData
How do I get a blank value in the DropDownList
? Should I build it into the SelectList
when I am creating it or is there some other means to tell the helper to auto create an empty value?
Lastly, if for some reason there is a server side error and I need to redisplay the screen with the DropDownList
, do I need to fetch the list values again to pass into the view model? This data is not maintained between posts (at least not when I pass it via my view model) so I was going to just fetch it again (it's cached). Am I going about this correctly?