0

I leave this in the default css file for the site

.hover  a
{
    background-color:Gray;
    text-decoration:none;
}

.hover  a:hover
{
    background-color:Red;
    color:White;
}

and in _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"}) 
}

Only the class hover->a is effective, it is also strange to me as to why the URL when my mouse is over the Log On link adds "?length=7", what is that ?

Mackintoast
  • 1,397
  • 5
  • 17
  • 25
  • Not sure if it's intended or not (and it doesn't solve your problem in any way), but your only applying the hover class to the "Logon"link and not the "Log Off" link. – Joshua Enfield Feb 17 '12 at 17:42

2 Answers2

0

To be complete.

The CSS

Replace .hover a:hover with a.hover:hover

The ?Length issue

This link explains why it happens: Why does Html.ActionLink render “?Length=4”

According to the linked post changing the ActionLink to the following should fix that.

Html.ActionLink("Log On", "LogOn", new { controller = "Account" }, new { @class = "hover" })

or if you are coming from the Account controller already, then you don't need to specify it again in the link and null will also work. null causes the link to go to the action in a controller the view came from to begin with.

Html.ActionLink("Log On", "LogOn", null, new { @class = "hover" })

Bascially you were using the wrong override of ActionLink.

Community
  • 1
  • 1
Nope
  • 22,147
  • 7
  • 47
  • 72
0

Your css should be:

a.hover
{
    background-color:Gray;
    text-decoration:none;
}

a.hover:hover
{
    background-color:Red;
    color:White;
}
Zach Green
  • 3,421
  • 4
  • 29
  • 32