我将此保留在网站的默认css文件中
.hover a
{
background-color:Gray;
text-decoration:none;
}
.hover a:hover
{
background-color:Red;
color:White;
}
和_LogonPartial.cshtml
@if(Request.IsAuthenticated) {
<text>Welcome <strong>@User.Identity.Name</strong>!
[ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text>
}
else {
@Html.ActionLink("Log On", "LogOn", "Account", new { @class="hover"})
}
只有班级hover-&gt; a有效,我也很奇怪为什么我的鼠标在登录链接上的URL添加“?length = 7”,那是什么?
答案 0 :(得分:0)
完成。
CSS
将.hover a:hover
替换为a.hover:hover
?长度问题
此链接解释了它发生的原因:Why does Html.ActionLink render “?Length=4”
根据链接的帖子更改ActionLink
以下内容应该解决这个问题。
Html.ActionLink("Log On", "LogOn", new { controller = "Account" }, new { @class = "hover" })
或者如果您已经来自帐户控制器,那么您不需要在链接中再次指定它,null
也可以。 null
导致链接转到视图来自的控制器中的操作。
Html.ActionLink("Log On", "LogOn", null, new { @class = "hover" })
基本上你使用了错误的ActionLink
覆盖。
答案 1 :(得分:0)
你的css应该是:
a.hover
{
background-color:Gray;
text-decoration:none;
}
a.hover:hover
{
background-color:Red;
color:White;
}