문제

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.

도움이 되었습니까?

해결책

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" });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top