按照链接后的下一页添加css类(asp.net-mvc razor)

时间:2017-08-25 05:53:29

标签: css asp.net-mvc razor

我有jQuery的下拉菜单。我需要在跟随链接后激活下一页中的菜单项和子菜单项。 之前:

<div class="menu__item">Menu Item 1</div>
<div class="menu__item__submenu">
     @Html.ActionLink("Submenu item 1", ..., new { @class = "submenu__item" })

后:

<div class="menu__item menu__item-active">Menu Item 1</div>
<div class="menu__item__submenu submenu-active-js">
     @Html.ActionLink("Submenu item 1", ..., new { @class = "submenu__item submenu__item-active" })

我怎么能成功?

2 个答案:

答案 0 :(得分:0)

这只是不完美代码的例子。您需要根据您的代码进行自定义。

像:

android:groupIndicator="@null"

答案 1 :(得分:0)

我是这样的: 在控制器中,我们添加到从子菜单调用的方法

public ActionResult CertInstall()
    {
        ViewData["MenuItemActive"] = "menu__item-active";
        ViewData["SubMenuActive"] = "menu__item__submenu-active";
        ViewData["CertInstal_SubMenuActive"] = "submenu__item-active";
        return View(ViewData);
    }
菜单视图中的

&#13;
&#13;
<menu class="menu-wrap">
    @Html.ActionLink("Main", "Index", "Home", null, new {@class = "menu__item"})
    <div class="menu__item @ViewData["MenuItemActive"]">
        Menu Item 1
    </div>
    <div class="menu__item__submenu @ViewData["SubMenuActive"]">
        @Html.ActionLink("Certificate Order", "CertOrder", "Home", null, new { @class = "submenu__item " + @ViewData["CertOrder_SubMenuActive"] })
        @Html.ActionLink("Certificate Install", "CertInstall", "Home", null, new { @class = "submenu__item " + @ViewData["CertInstal_SubMenuActive"] })
     </div>
        @Html.ActionLink("Contacts", "Contacts", "Home", null, new { @class = "menu__item" })
</menu>
&#13;
&#13;
&#13;

PS。是的,这是一个糟糕的代码,但我不知道如何做得更好