Mogli
Mogli

Reputation: 2012

Applying css on ActionLink in mvc?

I am working in mvc5. I made a simple action link in a view using this syntax

@Html.ActionLink("Manage List", "Index", new { @class = "ManageLink" });

But css was not working untill i added controller name like this:

@Html.ActionLink("Manage List", "Index",new { controller = "ControllerName" }, new { @class = "ManageLink" });

I want to know why we need to define controller name here while it is quite obvious that every view is related to some action method of a controller ? I am very new to mvc so need to know these kind of things.

Thanks for the help.

Upvotes: 0

Views: 1997

Answers (1)

Tieson T.
Tieson T.

Reputation: 21191

You could also have fixed this by simply specifying the name of the optional parameter you wanted to set:

@Html.ActionLink("Manage List", "Index", htmlAttributes: new { @class = "ManageLink" });

Otherwise, the Razor engine has to try to figure out which overload of the ActionLink method you're trying to call; sounds like in your case it thought the third argument was for the routeValues parameter.

This would also work:

@Html.ActionLink("Manage List", "Index", "ControllerNameHere", new { @class = "ManageLink" });

Upvotes: 1

Related Questions