I’ve got a situation where I have a project with several models that have a “Staff” property (for things like the Department head, who a task is assigned to, etc). I’d like to create a partial view for editing all these that uses a dropdown, so I can just use Html.EditorFor when I want an editor for any of them.
The problem that I’m having is figuring out where to get the data to build the list of staff you can select. It’s a list of staff, which comes from the database. Where does the partial view get that list from? Should it just have some logic in the view to load it whenever it’s needed, or should the ViewModel of whatever I’m editing contain the entire list?
I’m pretty new to MVC, so I’ve been struggling a bit with issues like this. Thanks for any help. 🙂
Sounds like the perfect candidate for a custom ViewModel. I always refer folks to the Nerd Dinner tutorial which covers almost this same exact thing (populating a drop box). Check it out here!