How to determine the search path of Controllers and Views?

4

I'm studying ASP.NET Core MVC on a MacOS.

When I create a new project, the IDE automatically arrows my Views in a folder called "Home". If I change the name of this folder or change the Folder Views I get an error message when executing the project:

  

"InvalidOperationException: The view 'Index' was not found."

I opened all the files to see if any of them were going to the Views path but I did not succeed.

    
asked by anonymous 17.12.2017 / 06:12

2 answers

3

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

The action inside it example public IActionResult Index will look inside the Home folder for the Index.cshtml file. This is law.

This in ASP.NET Core: To rename the routes in the URL field you should 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 at: link

    
18.12.2017 / 13:49
1

In the file Startup.cs you must have a method named Configure . There you will find the routes configured, and one of them is something for the Home driver, which no longer exists. Change to the controller you created and restart the server.

routes.MapRoute(
              name: "SomeDescriptiveName",                      
              template: "AnotherNameThatPointsToHome/{action=Index}/{id?}",
              defaults: new { controller = "Home"} 
              );
18.12.2017 / 13:51