darshan doshi
darshan doshi

Reputation: 44

Regarding MVC3 master page and user control

Regarding MVC3 MASTER PAGE ISSUE I have one master page and inside that master page i have used one usercontrol. Now inside that usercontrol I have bind out one dropdown list from database from actionresult.

Now the problem is that whenever I use another view i have to call that action result for binding that dropdown list again and again in all other pages which include my master page. How could I prevent this from happening? Remember my friends, I am using MVC3.

Upvotes: 0

Views: 332

Answers (2)

Matija Grcic
Matija Grcic

Reputation: 13381

If you don't need to check data from DB then make a static dictionary and bind it to the DropDownListFor:

private static readonly Dictionary<int, string> yourData
    = new Dictionary<int, string>
{
    { "1", "Your data one" },
    { "2", "Your data two" }
};

Regards

Upvotes: 0

alok_dida
alok_dida

Reputation: 1733

As per your question, I understand that you want do not want to make DB call on your execution of each view as you included Dropdown in masterpage.

To overcome this problem, you need to implement ouputcache for that usercontrol (partialpage). Please find more details here. Do let me know if you still have any query.

Upvotes: 1

Related Questions