.Net Core MVC application running in Visual Studio cannot find views

I created a new .Net Core MVC web application in Visual Studio 2015. The IDE is completely updated and I have the latest SDK.net core installed. It consists of a solution file and several project files. I can successfully launch it and go to the home page.

Then I opened the root folder (solutions folder) in Visual Studio Code and tried to start it. Everything seems to have started fine, however it cannot find the default view for "Views / Home / Index.cshtml".

I get the following error:

InvalidOperationException: Index view not found. The following locations were searched: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml

The program.cs file is as follows:

var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();

The .json project has the following:

"buildOptions": {
  "emitEntryPoint": true,
  "preserveCompilationContext": true
},

"publishOptions": {
  "include": [
    "wwwroot",
    "Views",
    "Areas/**/Views",
    "appsettings.json",
    "web.config"
  ]
}

, , , , VSC.

?

+4
2

:

  • VS Code.
  • ​​ :

Recommended Build Configuration

, , , .

, , - (cwd property) .vscode\launch.json:

Default configuration

-:

fixed config

WebProject Project root .

, !

+7

. , ASP.NET 4.5 (MVC5).

, Startup.cs:

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});

, , , . http://mysite/Home/Index

            • Index.cshtml

, , .

0

Source: https://habr.com/ru/post/1654098/


All Articles