通过选定我想你的意思是使用CSS亮点,不是吗?如果是这样的话我建议你写一个自定义的HTML辅助生成这些链接:
public static IHtmlString MenuItem(
this HtmlHelper htmlHelper,
string text,
string action,
string controller
)
{
var li = new TagBuilder("li");
var routeData = htmlHelper.ViewContext.RouteData;
var currentAction = routeData.GetRequiredString("action");
var currentController = routeData.GetRequiredString("controller");
if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) &&
string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase))
{
li.AddCssClass("active");
}
li.InnerHtml = htmlHelper.ActionLink(text, action, controller).ToHtmlString();
return new HtmlString(li.ToString());
}
,然后你的布局中使用助手:
<ul>
@Html.MenuItem("link 1", "Action1", "Controller1")
@Html.MenuItem("link 2", "Action2", "Controller2")
...
</ul>
,现在所有剩下的就是在你的CSS类中定义.active
规则:
.active {
... something fancy to pop the currently selected link from the others
}