How do I determine the search path for Controllers and Views?

Asked

Viewed 501 times

4

I’m studying ASP.NET Core MVC on a macOS.

When I create a new project, the IDE automatically arrow my Views into a folder called "Home". If I change the name of that folder or change the folder views I get an error message while running the project:

"Invalidoperationexception: The view 'Index' was not found. The following Locations Were searched:"

I opened all the files to see if any of them set the Views path but I was not successful.

2 answers

3


The name of your controller for example HomeController by law will fetch everything inside the Home folder.

The action within her example to public IActionResult Index will search inside the folder Home the file Index.cshtml. That is law.

This in ASP.NET Core: to rename the routes in the URL field you must go to the file Startup.cs in public void Configure and do the following:

app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "Nome que vai ser chamado na url",
                template: "{controller=Sua-Controller}/{action=Sua-Action}/{Seu-ID-se-houver?}");
        });

You can search for more on: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing

  • 1

    Felipe, thank you so much for the strength friend. I can not test now, but already marked as answered.

1

  • vnbrs, thank you so much for the help my good.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.