Add a New Razor Page To ASP.NET 5 Project

ASP.NET Razor Pages is a new web framework for building dynamic pages using templates, partials, and code-behind files. Razor Pages has been built from the ground up with a singular focus on creating simple yet powerful web pages. There’s no view engine to decide between server-side or client-side templating, so you have the option to write your markup in whatever way works best for you and your application.

Razor Pages provides a fresh take on a classic ASP.NET page that combines the simplicity of a template engine with ease of use of live code at runtime—and gives you complete control over how it all gets delivered to the browser. The two main benefits of this design are: 1) people can write markup in Razor syntax or TypeScript, JavaScript, C#, F#, etc. side-by-side in the same page and 2) you can run your application on both server and client with full fidelity using a single code base.

Adding a new page

When it comes to adding new pages and content to an existing project using Visual Studio is a process that allows us to scale our application easily without breaking existing code.

To add a new page to an existing project, Open the project using Visual Studio 2019 and right click on the Pages folder.

From the menu, Click on Add

Click on Razor Page…

From the Add new item window you have the option to select what kind of Razor page you like. In our case we select an Empty page.

Adding the Page to the Header menu

To add the page to the header menu, open the _layout.cshtml page located under the Shared folder and add it to the list of pages.

The easiest way to do it is to copy existing page and change the name and link.

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.