Here we will see how to create a sample asp.net core 2.0 razor page application in Visual Studio.
In Visual Studio select New Project option .In the new project template select .NET Core –> ASP.NET Core Web Application option.
Enter application name and select OK.
In the next screen select ASP.NET Core 2.0 in the dropdown and Web Application in the template
In the solution explorer you can see the following important items:
- wwwroot Contains static files such as css,js and images.
- Pages Folder for Razor Pages.
- appsettings.json settings defined using JSON.
- Program.cs Starts the ASP.NET Core app.
- Startup.cs Configures request pipeline.
If you expand the pages folder you can see the following razor pages:
If you look in the in the Startup class in StartUp.cs file you can see the following methods:
public void ConfigureServices(IServiceCollection services)
//Add Razor Pages in pipeline
public void Configure(IApplicationBuilder app)
the UseMvc() method above adds MVC to the request pipeline.
Now if you look at any razor page you can see @page directive at the top.This directive makes a cshtml file as a action method.So the page handles the request without needing separate controller.
There is no controller but if you execute the application you can see the response:
The urls are mapped to razor pages based on the path of the page.So /Index will match /Pages/Similarly /Pages/Employee/Details.cshtml / will match Employee/Details