如何突出在asp.net MVC3所选主页的标签 [英] how to highlight selected tab of master page in asp.net mvc3

查看:108
本文介绍了如何突出在asp.net MVC3所选主页的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创造了很多的努力,一个母版页,但我无法弄清楚如何使基于用户点击来选择我的标签。
我用一个方法来做到这一点,但发现非常复杂的,因为我有过每个我的控制器,我不喜欢它一个可视数据,下面是如何我做的控制器code

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";

在我的母版页我写一个jQuery像下面让标签高亮显示。

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...

请建议
我已经找到了一个很好的链接活动菜单项 - asp.net MVC3母版页
但它表明有我不能够回答明白,我怎么利用我的code和在何处写入code在我的项目。

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.

推荐答案

使用的回答您发现
要创建辅助类添加新的类你的项目,即像这样

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
}

添加到您的HomeController的方法(可能你已经拥有它们):

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>

最后在你的CSS文件中声明

And finally in your css file declare

.current{background-color:red;}

这篇关于如何突出在asp.net MVC3所选主页的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆