I am using:
- Asp.net MVC3
- Ninject
- Repository pattern with Entity Framework 4.0
On an admin page there is a select where the user can choose a product group.
The dropdown is in a partial view in EditorTemplates. The partial view today handles the data access itself. My question is, what is the best practice for this partial view?
Is it:
- Keep it as it is
- Move the select to a view that is rendered by an Action, so that the Controller can get its dependencies from Ninject
- The Partial View gets both the ID of the product group selected AND all the groups from the view that invokes it.
- ?
Above i described a specific scenario, but I guess that it is a common problem, and I haven’t found a good way of doing it on SO.
As long as the partial view is called once, I’d go with option 2. I’d look into MiniProfiler to see all the calls to the database. You shouldn’t be doing much of that if any in your views. If it’s being called for each item in the select or if you have the data already, it would be faster to pass that data directly to the view.