【发布时间】:2014-03-03 23:32:37
【问题描述】:
我正在使用 Asp.net MVC4,我试图在 Html.MenuLink 中添加一个“锚”而不重写新的 MenuLink
这是我的html链接
<li class="nousjoindre">
@Html.MenuLink("Join us", "Index", "JoinUs", null, new { @class = "active" })
</li>
渲染时生成这个html
<li class="join">
<a href="/JoinUs">Join us</a>
</li>
和目标锚
<div>
<h1 id="PointHere">Point here</h1>
</div>
和 MenuLink 代码
public static MvcHtmlString MenuLink( this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues = null, object htmlAttributes = null)
{
string currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action");
string currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller");
if (controllerName == currentController)
{
if (htmlAttributes == null)
htmlAttributes = new { @class = "selected" };
return htmlHelper.ActionLink(
linkText,
actionName,
controllerName,
routeValues,
htmlAttributes
);
}
return htmlHelper.ActionLink(linkText, actionName, controllerName);
}
Html.MenuLink 的第 4 个参数用于向目标链接添加参数,但这不是我需要的。
我想要一个像localhost/JoinUs#PointHere这样的网址
感谢您的帮助
【问题讨论】:
-
没有这样的
Html.MenuLinkASP.NET MVC 4 内置助手。请附上您正在使用的自定义助手的相关源代码。 -
对不起,我忘记了!!这里我包含了 MenuLink 代码
标签: c# html asp.net-mvc-4