ASP.NET MVC:标签ASCX - 调整CSS类基于当前的页面?标签、页面、NET、ASP

2023-09-04 02:30:42 作者:香烟如寂寞

我有一个ASP.NET MVC应用程序,我想实现的标签,这将导航到不同的页面。该标签被实现为一个简单的ASCX用户控件,例如:

I have an ASP.NET MVC application and I'm trying to implement tabs which will navigate to different pages. The tabs are implemented as a simple ASCX usercontrol, e.g.

<ul>
    <li><a href="xyz1.html">Number One</a></li>
    <li class="activePage"><a href="xyz2.html>Number Two</a></li>
    <li><a href="xyz1.html">Number Three</a></li>
</ul>

当前页面通过activePageCSS类设计(在标签#2上面的演示code)。

The current page is designed through the "activePage" css class (in above demo code on tab #2).

什么是一个简单而有效的方式传达给哪个标签应该得到activePage类,而不需要修改它的每一页的ASCX?

What is an easy and efficient way to communicate to the ASCX which tab should get the activePage class without having to modify it for each page?

样品code是高度AP preciated。

Sample code is highly appreciated.

推荐答案

请问一个解决方案,如使用jQuery突出你的活动标签工作?

Would a solution such as using jQuery to highlight the active tab work for you?

您可以选择在&lt; A&GT;包含等于当前页面的href属性,而一个类添加到父&LT;李&GT;

You could select the <a> that contains the href attribute that equals the current page, and add a class to the parent <li>.

这是我能想到的最简单的办法。

This is the simplest solution I can think of.

 
精彩推荐
图片推荐