0

I honestly can't see why on earth this doesn't work, but here it goes:

@Html.ActionLink("About", "About", "Home", new { @class = "nav-link" }, null)

This should produce:

<a href="/Home/About" class="nav-link">About</a>

But instead it produces:

<a href="/Home/About?class=nav-link">About</a>

All the annotations for adding a class to an ActionLink, tells me to do it that way. What am I doing wrong?

MortenMoulder
  • 6,138
  • 11
  • 60
  • 116
  • Could you remove `, null`? The overload that takes 4 arguments should be the correct one. Try: https://stackoverflow.com/a/21196582/1661209 – Max Dec 30 '17 at 16:02
  • What version of mvc are you using? – StaticBeagle Dec 30 '17 at 16:03
  • Possible duplicate of [How do I apply a CSS class to Html.ActionLink in ASP.NET MVC?](https://stackoverflow.com/questions/1444495/how-do-i-apply-a-css-class-to-html-actionlink-in-asp-net-mvc) – Max Dec 30 '17 at 16:04

1 Answers1

0

Ah, apparently it's supposed to be:

@Html.ActionLink("About", "About", "Home", new object {}, new { @class = "nav-link" })

Weird.

MortenMoulder
  • 6,138
  • 11
  • 60
  • 116