<li class="rtsLI" id="Summary"><a href="javascript:void(0);" onclick="javascript:rtsXXX.OnClientTabSelected(this, 0);" class="rtsLink"><span class="rtsTxt">Test</span></a></li>
上面我有以下ActionLink的更换:
<li class="rtsLI" >@Html.ActionLink("test1", "Index", new { Area = "Area1", Controller = "controller1" }, new { @class = "rtsLink rtsTxt"})</li> "
在第一个CSS是工作的罚款。 但是,使用ActionLink的时候,CSS不工作。 谢谢
最好的选择将是使用@Url.Action
扩展方法
<li class="rtsLI" id="Summary"><a href="@Url.Action("Index", new { Area = "Tools", Controller = "UserSecurity" })" class="rtsLink"><span class="rtsTxt">User Security</span></a></li>
该标准的ActionLink助手总是HTML编码的链接文本。 这意味着,如果你想里面渲染HTML,你不能使用它。 你有3种可能性:
- 修改你的CSS,这样你就不需要链接内,从而使跨度
rtsTxt
类可以直接应用于链接 编写自定义的ActionLink助手不HTML编码的文本,这将让你产生相同的标记:
public static class ActionLinkExtensions { public static IHtmlString ActionLinkUnencoded( this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes ) { var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); var link = new TagBuilder("a"); link.MergeAttributes(new RouteValueDictionary(htmlAttributes)); link.Attributes["href"] = urlHelper.Action(actionName, routeValues); link.InnerHtml = linkText; return new HtmlString(link.ToString()); } }
然后:
<li> @Html.ActionLinkUnencoded( "<span class=\"rtsTxt\">User Security</span>", "index", new { area = "Tools", controller = "UserSecurity" }, new { @class = "rtsLink" } ) </li>
使用Url.Action帮手:
<li class="rtsLI"> <a href="@Url.Action("index", new { area = "Tools", controller = "UserSecurity" })" class="rtsLink"> <span class="rtsTxt">User Security</span> </a> </li>
编写代码是这样的:
<li class="rtsLI" >@Html.ActionLink("<span class='rtsTxt'>User Security</span>", "Index", new { Area = "Tools", Controller = "UserSecurity" }, new { @class = "rtsLink"})</li>`