Nistor Alexandru
Nistor Alexandru

Reputation: 5393

Creating a navigation for entire website

HI I am just learning asp.net mvc 3 and I am tryng to create a common menu for my entire application.I understand I can do that in _Layout.cshtml file witch is the default template for every page.

Now I have looked into sections for adding a template insite _Layout.cshtml but from what I can gather I need to define the section in every view.

I already have the logic for accesing the data defined in a separate class.All I need is to call the method witch will return a Dictionary<string , List<string>> , and then display the data by looping into it.

Aldo I could probably do this directly inside the Index.cshtml file by using the razor syntax I believe there must be a better way

So is there a way to create a template that can then bee added inside the _Layout.cshtml?

Upvotes: 0

Views: 109

Answers (2)

Ulises
Ulises

Reputation: 13419

Creating a section for the menu on each view could work but I think another approach could be easier to mantain. On your layout itself use @Html.Partial to render your menu. Then on that partial view you could have all kinds of operations, such as database access, in one single spot.

Here is an article on how to do exactly this: http://techbrij.com/981/role-based-menu-asp-net-mvc

Upvotes: 1

doreye01
doreye01

Reputation: 500

Was just looking into something similar. Hopefully partial views are your answer, this is a template you can re use and stick on any page. Information found here.

Upvotes: 1

Related Questions