0
对于使用不是最好的imo的Html帮助器方法的设置,因为我使用静态字段。在菜单中设置当前,当前和当前元素之后
public enum CurrentState
{
BeforeCurrent,
AfterCurrent
}
public static CurrentState currentState = CurrentState.BeforeCurrent;
public static MvcHtmlString ActiveActionLink(this HtmlHelper helper, string linkText, string actionName, string controllerName, bool checkAction = true)
{
string currentAction = helper.ViewContext.RouteData.GetRequiredString("action");
string currentController = helper.ViewContext.RouteData.GetRequiredString("controller");
if ((controllerName == currentController) && checkAction && (actionName == "Index"))
{
currentState = CurrentState.BeforeCurrent;
}
if ((controllerName == currentController) && checkAction && (actionName != currentAction))
{
if (currentState == CurrentState.BeforeCurrent)
{
return helper.ActionLink(linkText, actionName, controllerName, null, new { @class = "beforeCurrent" });
}
else if (currentState == CurrentState.AfterCurrent)
{
return helper.ActionLink(linkText, actionName, controllerName, null, new { @class = "afterCurrent" });
}
}
if ((controllerName == currentController) && (!checkAction || (actionName == currentAction)))
{
currentState = CurrentState.AfterCurrent;
return helper.ActionLink(linkText, actionName, controllerName, null, new { @class = "current" });
}
return helper.ActionLink(linkText, actionName, controllerName);
}
我有菜单的两个层次,这就是为什么我使用checkAction参数:
- 主菜单 - @ Html.ActiveActionLink(Resources.Global.mainMenuBoard, “索引”, “董事会”,checkAction :假)
- 侧菜单 - @ Html.ActiveActionLink(@ Resources.Global.managementOverview,“索引”,“管理”)
和侧面菜单我需要知道,如果它的后电流之前(重叠项目...)。
这是一种改进方法吗? 此外,我必须说,我也使用JavaScript,但它也必须适用于JavaScript禁用。
它是无用的,我不知道静态是相同的每个网站的实例... – mrzepa