asp.net mvc和css:菜单选项卡保持高亮显示选择 [英] asp.net mvc and css: Having menu tab stay highlighted on selection

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

问题描述

有更好的方法吗?



我有一个HTML助手扩展方法,用于检查当前标签菜单是否是所选的菜单,然后选择.selected css类。我把每个li中的html.IsSelected链接作为

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

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


$

解决方案

如果你可以使用javascript解决方案,请查看 jQuery UI Accordion 插件如何处理此问题。基本上,您可以通过在加载网页时检查请求网址来选择基于控制器的突出显示的标签。



或者,您可以为每个标签设置ViewBag项对应于选项卡的类值。将当前选项卡的值设置为活动css类,将其他值设置为空(或其默认值)。然后您可以使用:

 < li id =HomeTabclass =<%= ViewBag.HomeTabClass%> 。 /> 
< li id =OtherTabclass =<%=(string)ViewBag.OtherTabClass%> />

然后在控制器中为ViewData变量设置正确的值。

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


Is there a better way to do this?

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)%>" >

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

is this clean or is there a better way?

解决方案

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.

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 %>" />

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天全站免登陆