我的MVC3剃刀视图上有一个动作链接。它们有一个如下的动作链接:
@Html.ActionLink("Click Here (I do not have Middle Name)",
"", "", new { @class = "button lines-6" })我要将操作链接文本更改为:
<strong>Click Here </strong> (I do not have Middle Name)
有没有办法解决这个问题。
非常感谢
发布于 2012-06-15 18:34:02
使用URL.Action而不是操作链接,您可以更好地控制内容。
<a href="@Url.Action("Index", "Home")" class="button lines-6">
<strong>Click Here </strong> (I do not have Middle Name)
</a>发布于 2012-06-15 19:04:51
自定义HtmlHelper扩展是另一种选择。
public static string ActionLinkSpan( this HtmlHelper helper, string linkText, string actionName, string controllerName, object htmlAttributes )
{
TagBuilder spanBuilder = new TagBuilder( "span" );
spanBuilder.InnerHtml = linkText;
return BuildNestedAnchor( spanBuilder.ToString(), string.Format( "/{0}/{1}", controllerName, actionName ), htmlAttributes );
}
private static string BuildNestedAnchor( string innerHtml, string url, object htmlAttributes )
{
TagBuilder anchorBuilder = new TagBuilder( "a" );
anchorBuilder.Attributes.Add( "href", url );
anchorBuilder.MergeAttributes( new ParameterDictionary( htmlAttributes ) );
anchorBuilder.InnerHtml = innerHtml;
return anchorBuilder.ToString();
}您也可以尝试上述建议选项的不同风格:
<li id="home_nav"><a href="<%= Url.Action("ActionName") %>"><span>Span text</span></a></li>https://stackoverflow.com/questions/11048977
复制相似问题