visual-studioasp.net-coreasp.net-core-2.0razor-pagesasp.net-core-mvc-2.0

Template for new ASP.NET Core Razorpage in Visual Studio 2017


Starting to work with a web app and following the steps here to use razor pages

Is there a template (either in VS or elsewhere) for adding a new razorpage (ie the cshtml and the cshtml.cs files)? As a workaround I created an MVC View page (with the .cshtml ext) and then created a .cs file and renamed it to match the naming pattern.

I'm having problems running the scaffolding as well but that is a separate issue.


Solution

  • You can do this in the latest version of Visual Studio 2017 just by using Add New Item and choosing Razor Page.

    You can also use dotnet new. For example:

    dotnet new page --name MyPage
    

    See the documentation for dotnet new. You can always get started by just running dotnet new alone to see the available templates.