In the default asp.net mvc project, in the Site.Master file, there is a menu navigation list:
Using MVC3 with a Razor View offers another option:
_Layout.cshtml:
- @Html.ActionLink("Home", "Index", "Home")
- @Html.ActionLink("Disclaimer", "About", "Home")
HomeController:
public ActionResult Index() {
ViewBag.NavClassHome = "active";
return View();
}
public ActionResult About() {
ViewBag.NavClassAbout = "active";
return View();
}
If you want to preserve this for a postback as well, you have to assign the ViewBag value here as well:
[HttpPost]
public ActionResult Index() {
ViewBag.NavClassHome = "active";
return View();
}
[HttpPost]
public ActionResult About() {
ViewBag.NavClassAbout = "active";
return View();
}
Tested and working fine for me, but you will have a css class name in your server side code.