I was wondering what the best practice is when populating commonly used dropdownlists in ASP.NET MVC. For instance, I have a Country and State select which is used often in my application. It seems dirty to populate viewmodel and bind to that viewmodel from my controller for every single view I want to contain such a dropdownlist.
How do people populate their dropdownlists in such cases? – custom baseclass with this baked in? Helper classes, etc?
Thanks in advance,
JP
You can have a
RequiresStateListattribute to inject that common functionality to the actions that need it.And your action
Now you can get that list from the ViewData in your view.