0

i have created a master page with lots of effort but i am not able to figure out how to make my tab selected based on the user click. i have used one method to do that but finding very complicated as i have pass a viewdata from each of my controller which i dont like it, below is how i have done code in controller

ViewData["ActiveMenu"] = "Inbox";

and in my master page i have written a jquery like below to make the tab highlighted.

$('#lnkInbox').mouseout(function () {
            $('#aInbox').removeClass('aInbox-Hover');
            $('#aInbox').addClass('aInbox');

            //put hover effect on the selected menu
            var activeMenu = '<%:ViewData["ActiveMenu"] %>';
            if (activeMenu == "Account") {
                $('#aAccount').removeClass('aAccount');
                $('#aAccount').addClass('aAccount-Hover');

            }});

this is how i am doing but is there any other way i can do that...

please suggest i have found one good link active menu item - asp.net mvc3 master page but the answer which is showed there i am not able understand how to i utilize in my code and where to write the code in my project.

Community
  • 1
  • 1
aamankhaan
  • 491
  • 1
  • 9
  • 35

1 Answers1

0

Use the answer you found. To create helper class add new class to you project, i.e. like this

public static class LinkHelpers
{
//copy here the first block of code from the answer
}

Add to your HomeController methods (probably you already have them):

public class HomeController : Controller
{
   public ActionResult About()
   {
     return View()
   }
   public ActionResult Index()
   {
     return View()
   }
}

Create respective views and add to your master page

<ul>
    <li>@Html.MenuLink("Main", "Index", "Home")</li>
    <li>@Html.MenuLink("About us", "About", "Home")</li>
</ul>

And finally in your css file declare

.current{background-color:red;}
Community
  • 1
  • 1
Cheburek
  • 2,103
  • 21
  • 32
  • hi, thanks for your comment but where should i add the static class (in my controller create a static class or in the action of the controller) – aamankhaan Apr 26 '12 at 05:28
  • @aamankhaan No, create a separate file, i.e. in the root of your project – Cheburek Apr 26 '12 at 07:54