I'm using Visual Studio 2017 and .NET Core 2.2.
Do the following:
- New Project and select ASP.NET Core Web Application (press OK)
- This takes you to a second dialog where you can select Web Application (has example Razor Pages) or Web Application (Model-View-Controller).
I want to point out one difference between the two options, when looking at Startup.cs:
If you select just Web Application, you will get this at the bottom of the Configure function:
app.UseMvc();
If you select Web Application (Model-View-Controller), you will get this:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
So, the MVC project defines some type of routing. Which specifically tells me that it is going to use the Home Controller by default and if no action is specified then the Index(.cshtml) action will be used.
The first option (Razor pages), routes nothing.
I don't understand. Does this mean that if you don't define a MapRoute it will just always use the Index(.cshtml) action?
Because With the MVC Project, if I used just:
app.UseMvc();
and defined no MapRoute, I would get a 404. How is the Razor app defining it's routing (and where)?