asp.net MVC和css:有菜单选项卡上选择保持突出 [英] asp.net mvc and css: Having menu tab stay highlighted on selection

查看:189
本文介绍了asp.net MVC和css:有菜单选项卡上选择保持突出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有更好的方式来做到这一点?

Is there a better way to do this?

我来检查,如果当前选项卡菜单中选择之一的HTML辅助扩展方法,然后选择.selected CSS类与否。我把每个李html.IsSelected链接为

I have an HTML helper extension method that checks if the current tab menu is the the selected one and then chooses .selected css class or not. I put the html.IsSelected link in each li as

<li class="<%=Html.IsSelected(string a, string b)%>" >

,其中a是选项卡名称,b是ViewData的分配

where a is the tab name and b is ViewData assigned.

这是干净的还是有更好的办法?

is this clean or is there a better way?

推荐答案

如果你能忍受一个JavaScript的解决方案,怎么看待的 jQuery UI的手风琴插件处理这个问题。从本质上讲,你可以通过检查请求的URL,当加载页面时选择基于控制器上突出显示的标签。

If you can live with a javascript solution, look at how the jQuery UI Accordion plugin handles this. Essentially, you can choose the highlighted tab based on the controller by examining the request url when the page is loaded.

另外,你可以设置一个ViewBag项目为每个对应标签的类值选项卡。设置为当前选项卡的活跃CSS类和其他空(或它们的默认值)的值。然后你可以使用:

Alternatively, you can set a ViewBag item for each tab that corresponds to the tab's class value. Set the value for the current tab to the active css class and the others to empty (or their defaults). Then you can use:

<li id="HomeTab" class="<%= ViewBag.HomeTabClass %>" />
<li id="OtherTab" class="<%= (string)ViewBag.OtherTabClass %>" />

在你的控制器,你会再建立正确的价值观为ViewData的变量。

In your controller, you would then set up the proper values for the ViewData variables.

ViewBag.HomeTabClass = "tab activeTab";
ViewBag.OtherTabClass = "tab";

这篇关于asp.net MVC和css:有菜单选项卡上选择保持突出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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