ASP.NET Core 2 Razor

A Guide to ASP.NET Core 2 Razor Pages

Microsoft has introduced the concept of Razor page with Core 2.0. It is still same as existing MVC in some manner, but with a better approach. In Razor, model and controller are included within Razor page itself.

In MVC you need to define viewdata, controller action, routecollection, HTML helper etc. to tie up Model, View and Controller approach.

Any change in Model may also disturb the view behavior and it also need fixing at the same time. It makes the solution a little bit costly. Razor page approach is better in this situation where we have Razor view and the entire code behind file. It is less complex than MVC.


Sample Code of Razor Page Using inline Code Within a @functions Block:

Sample Code of Razor Page using code behind.

Razor view

Code behind:


It is like a webform with all the pros of MVC. It is very useful in page focused operations like reports and CRUD operations. It provides a simple and faster approach to develop a website. It also includes anti-forgery token validation automatically.

So, enjoy the website development with Razor pages in ASP.NET Core 2.


Also Read: Important changes in ASP.NET Core 3.0


Contributed By:

Arunodaya Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge