使用Fontawesome字体,我必须使它成为连接到高度的超链接。所以如何在hello tim @ test旁边显示图标?
<li>
<a href="#"><i class="fa fa-user" style="color:green"></i></a> @Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
</li>
<li><div style="display:inline">
<a href="#"><i class="fa fa-user" style="color:green"></i></a> @Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
</div>
</li>
<li>
<a href="#"><i class="fa fa-user" style="color:green"></i></a>
</li>
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
<ul class="nav navbar-nav navbar-right">
<li>
<a href="#"><i class="fa fa-user" style="color:green"></i></a>
</li>
<li>
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
}
}
else
{
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}
答案 0 :(得分:1)
@Html.ActionLink
只为您创建一个A
元素...所有@Html
方法都会执行此类操作...在您的第二个示例中,您将锚点放在另一个锚点中
在这种情况下,您需要对内容进行更多控制......在这种情况下,@Url.Route
是您想要将控制器/操作的路由仅注入A
元素,而图标在里面,以及其他内容。
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
{
<ul class="nav navbar-nav navbar-right">
<li>
<a href="@Url.Route("Index", "Manage")" title="Manage">
<i class="fa fa-user" style="color:green"></i>
Hello @User.Identity.GetUserName()!
</a>
</li>
<li>
@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, htmlAttributes: new { style: "display:inline;" }))
{
@Html.AntiForgeryToken()
<a href="javascript:void(0);" onclick="this.parentNode.submit();">
Log off
</a>
}
</li>
</ul>
} else {
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}
其他更改包括,将注销表单移动到简单地包装链接,并调整链接的操作以定位父级...您将navbar-right
分配给表单可能会使事情稍微过时。上面的表单不需要ID作为参考,因为它是注销链接的parentNode
。