Back to Aspnetcore

Visual Studio

aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start5.md

latest5.9 KB
Original Source

:::moniker range=">= aspnetcore-5.0 < aspnetcore-6.0"

This is the first tutorial of a series that teaches the basics of building an ASP.NET Core Razor Pages web app.

For a more advanced introduction aimed at developers who are familiar with controllers and views, see Introduction to Razor Pages.

[!INCLUDE Choose web UI]

At the end of the series, you'll have an app that manages a database of movies.

In this tutorial, you:

[!div class="checklist"]

  • Create a Razor Pages web app.
  • Run the app.
  • Examine the project files.

At the end of this tutorial, you'll have a working Razor Pages web app that you'll enhance in later tutorials.

Prerequisites

Visual Studio

[!INCLUDE]

Visual Studio Code

[!INCLUDE]

Visual Studio for Mac

[!INCLUDE]


Create a Razor Pages web app

Visual Studio

  1. Start Visual Studio and select Create a new project. For more information, see Create a new project in Visual Studio.

  2. In the Create a new project dialog, select ASP.NET Core Web Application, and then select Next.

  3. In the Configure your new project dialog, enter RazorPagesMovie for Project name. It's important to name the project RazorPagesMovie, including matching the capitalization, so the namespaces will match when you copy and paste example code.

  4. Select Create.

  5. In the Create a new ASP.NET Core web application dialog, select:

    1. .NET Core and ASP.NET Core 5.0 in the dropdowns.
    2. Web Application.
    3. Create.

The following starter project is created:

Visual Studio Code

The tutorial assumes familiarity with VS Code. For more information, see Getting started with VS Code.

  • Select New Terminal from the Terminal menu to open the integrated terminal.

  • Change to the directory (cd) that will contain the project.

  • Run the following commands:

    dotnetcli
    dotnet new webapp -o RazorPagesMovie
    code -r RazorPagesMovie
    

    The dotnet new command creates a new Razor Pages project in the RazorPagesMovie folder.

    The code command opens the RazorPagesMovie project folder in the current instance of Visual Studio Code.

[!INCLUDE]

Visual Studio for Mac

  1. Select File > New Solution.

  1. In Visual Studio for Mac earlier than version 8.6, select .NET Core > App > Web Application > Next. In version 8.6 or later, select Web and Console > App > Web Application > Next.

  1. In the Configure the new Web Application dialog:

    1. Confirm that Authentication is set to No Authentication.
    2. If presented an option to select a Target Framework, select the latest .NET 5.x version.
    3. Select Next.
  2. Name the project RazorPagesMovie and select Create.

<!-- End of VS tabs -->

Run the app

[!INCLUDE]

Examine the project files

Here's an overview of the main project folders and files that you'll work with in later tutorials.

Pages folder

Contains Razor pages and supporting files. Each Razor page is a pair of files:

  • A .cshtml file that has HTML markup with C# code using Razor syntax.
  • A .cshtml.cs file that has C# code that handles page events.

Supporting files have names that begin with an underscore. For example, the _Layout.cshtml file configures UI elements common to all pages. This file sets up the navigation menu at the top of the page and the copyright notice at the bottom of the page. For more information, see xref:mvc/views/layout.

wwwroot folder

Contains static assets, like HTML files, JavaScript files, and CSS files. For more information, see xref:fundamentals/static-files.

appsettings.json

Contains configuration data, like connection strings. For more information, see xref:fundamentals/configuration/index.

Program.cs

Contains the entry point for the app. For more information, see xref:fundamentals/host/generic-host.

Startup.cs

Contains code that configures app behavior. For more information, see xref:fundamentals/startup.

Troubleshooting with the completed sample

If you run into a problem you can't resolve, compare your code to the completed project. View or download completed project (how to download).

Next steps

[!div class="step-by-step"] Next: Add a model

:::moniker-end