Edit

Share via


Get started with ASP.NET Core MVC

Note

This isn't the latest version of this article. For the current release, see the .NET 10 version of this article.

Warning

This version of ASP.NET Core is no longer supported. For more information, see the .NET and .NET Core Support Policy. For the current release, see the .NET 9 version of this article.

By Rick Anderson

This tutorial teaches ASP.NET Core MVC web development with controllers and views. If you're new to ASP.NET Core web development, consider the Razor Pages version of this tutorial, which provides an easier starting point. See Choose an ASP.NET Core UI, which compares Razor Pages, MVC, and Blazor for UI development.

This is the first tutorial of a series that teaches ASP.NET Core MVC web development with controllers and views.

At the end of the series, you'll have an app that manages, validates, and displays movie data. You learn how to:

  • Create a web app.
  • Add and scaffold a model.
  • Work with a database.
  • Add search and validation.

View or download sample code (how to download).

Prerequisites

Create a web app

  • Start Visual Studio and select Create a new project.
  • In the Create a new project dialog, select ASP.NET Core Web App (Model-View-Controller) > Next.
  • In the Configure your new project dialog:
    • Enter MvcMovie for Project name. It's important to name the project MvcMovie. Capitalization needs to match each namespace when code is copied.
    • The Location for the project can be set to anywhere.
  • Select Next.
  • In the Additional information dialog:
    • Select .NET 9.0 (Standard Term Support).
    • Verify that Do not use top-level statements is unchecked.
  • Select Create.

Additional info dialog

For more information, including alternative approaches to create the project, see Create a new project in Visual Studio.

Visual Studio uses the default project template for the created MVC project. The created project:

  • Is a working app.
  • Is a basic starter project.

Run the app

  • Press Ctrl+F5 to run the app without the debugger.

    Visual Studio displays the following dialog when a project is not yet configured to use SSL:

    This project is configured to use SSL. To avoid SSL warnings in the browser you can choose to trust the self-signed certificate that IIS Express has generated. Would you like to trust the IIS Express SSL certificate?

    Select Yes if you trust the IIS Express SSL certificate.

    The following dialog is displayed:

    Security warning dialog

    Select Yes if you agree to trust the development certificate.

    For information on trusting the Firefox browser, see Firefox SEC_ERROR_INADEQUATE_KEY_USAGE certificate error.

Visual Studio runs the app and opens the default browser.

The address bar shows localhost:<port#> and not something like example.com. The standard hostname for your local computer is localhost. When Visual Studio creates a web project, a random port is used for the web server.

Launching the app without debugging by pressing Ctrl+F5 allows you to:

  • Make code changes.
  • Save the file.
  • Quickly refresh the browser and see the code changes.

You can launch the app in debug or non-debug mode from the Debug menu:

Start Debug and Start Without Debugging menus

You can debug the app by selecting the https button in the toolbar:

MvcMovie debug button

The following image shows the app:

Home or Index page

  • Close the browser window. Visual Studio will stop the application.