Monika Lachowicz
Monika Lachowicz

Reputation: 23

URL not found after setting asp-controller and asp-action attributes

I have no idea why my asp-controller don't want to show my pages. I have a controller named UserTemplatesController and this method there :

public ActionResult ADfind()
{
    return View();
}

the view attached to this method is called ADfind, so in my Razor page I tried to add this into another card like that :

<li><a asp-controller="UserTemplatesController" action="ADfind">ADfind</a></li>
<li><a asp-controller="UserTemplatesController" action="Index">Usermgr</a></li>
(...)

but everything what I see when I want to load this page is :

http://localhost:9505/UserTemplatesController
HTTP ERROR 404

Anyone have some idea to solve this ?

Upvotes: 0

Views: 900

Answers (1)

slfan
slfan

Reputation: 9139

It is a naming convention of ASP.NET MVC that controllers must be named controller at the end. The ASP.NET routing module adds Controller to the given name and searches for a class with this name. In your case your class should either be named UserTemplatesControllerController or your action should look like this:

<li><a asp-controller="UserTemplates" asp-action="ADfind">ADfind</a></li>
<li><a asp-controller="UserTemplates" asp-action="Index">Usermgr</a></li>

Furthermore the attribute for the action is called asp-action.

Upvotes: 4

Related Questions