I have a couple of list items in a shared _layout.cshtm
file (master page) in my MVC application.
something like:
-
Just wanted to share what i do:
I create folder App_Code
and add CustomHelpers.cshtml
. In it i create something like this:
@helper MainMenu(string SelectedItem) {
}
Than in my MasterPage (_Layout.cshtml) i add this where i want my menu to apear:
@CustomHelpers.MainMenu(ViewBag.SelectedMenu)
And than in my view, just like i change my page title, i change my selected menu:
@{
ViewBag.Title = "Welcome to my homepage";
ViewBag.SelectedMenu = "Home";
}
Got my idea from this tutorial: www.asp.net/mvc/videos/mvc-3/mvc-3-razor-helpers