2

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:

  1. Keep it as it is
  2. Move the select to a view that is rendered by an Action, so that the Controller can get its dependencies from Ninject
  3. The Partial View gets both the ID of the product group selected AND all the groups from the view that invokes it.
  4. ?

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.

1
  • can u show the code of editor template that shows data access code Jul 19, 2011 at 7:06

2 Answers 2

1

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.

1
  • So then I guess there is no "fancier" way of doing this! Thank you for your input, I will go for option #2.
    – Bebben
    Jul 19, 2011 at 8:16
1

I don't know, how much this answers you question, but I would go with option 2 :)

1
  • Two answers so far, both going for option 2! You both get a point, but Jason had a little more reasoning, so he will have to get the "Correct answer". Thanks!
    – Bebben
    Jul 19, 2011 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.