Get started with ASP.NET Core MVC

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.

This tutorial teaches the basics of building an ASP.NET Core MVC web app.

The app manages a database of movie titles. You learn how to:

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

At the end, you have an app that can manage and display movie data.

View or download sample code (how to download).

Prerequisites

Create a web app

  • From the Visual Studio select Create a new project.

  • Select ASP.NET Core Web Application and then select Next.

new ASP.NET Core Web Application

  • Name the project MvcMovie and select Create. It's important to name the project MvcMovie so when you copy code, the namespace will match.

    new ASP.NET Core Web Application

  • Select Web Application(Model-View-Controller), and then select Create.

New project dialog, .NET Core in left pane, ASP.NET Core web

Visual Studio used the default template for the MVC project you just created. You have a working app right now by entering a project name and selecting a few options. This is a basic starter project.

Run the app

Select Ctrl-F5 to run the app in non-debug mode.

Visual Studio displays the following dialog:

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.

  • Visual Studio starts IIS Express and runs the app. Notice that the address bar shows localhost:port# and not something like example.com. That's because localhost is the standard hostname for your local computer. When Visual Studio creates a web project, a random port is used for the web server.

  • Launching the app with Ctrl+F5 (non-debug mode) allows you to make code changes, save the file, refresh the browser, and see the code changes. Many developers prefer to use non-debug mode to quickly launch the app and view changes.

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

    Debug menu

  • You can debug the app by selecting the IIS Express button

    IIS Express

    The following image shows the app:

    Home or Index page

In the next part of this tutorial, you learn about MVC and start writing some code.

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.

This tutorial teaches the basics of building an ASP.NET Core MVC web app.

The app manages a database of movie titles. You learn how to:

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

At the end, you have an app that can manage and display movie data.

View or download sample code (how to download).

Prerequisites

Warning

If you use Visual Studio 2017, see dotnet/sdk issue #3124 for information about .NET Core SDK versions that don't work with Visual Studio.

Create a web app

  • From the Visual Studio select Create a new project.

  • Select ASP.NET Core Web Application and then select Next.

new ASP.NET Core Web Application

  • Name the project MvcMovie and select Create. It's important to name the project MvcMovie so when you copy code, the namespace will match.

    new ASP.NET Core Web Application

  • Select Web Application(Model-View-Controller), and then select Create.

New project dialog, .NET Core in left pane, ASP.NET Core web

Visual Studio used the default template for the MVC project you just created. You have a working app right now by entering a project name and selecting a few options. This is a basic starter project, and it's a good place to start.

Run the app

Select Ctrl-F5 to run the app in non-debug mode.

Visual Studio displays the following dialog:

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.

  • Visual Studio starts IIS Express and runs the app. Notice that the address bar shows localhost:port# and not something like example.com. That's because localhost is the standard hostname for your local computer. When Visual Studio creates a web project, a random port is used for the web server.

  • Launching the app with Ctrl+F5 (non-debug mode) allows you to make code changes, save the file, refresh the browser, and see the code changes. Many developers prefer to use non-debug mode to quickly launch the app and view changes.

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

    Debug menu

  • You can debug the app by selecting the IIS Express button

    IIS Express

  • Select Accept to consent to tracking. This app doesn't track personal information. The template generated code includes assets to help meet General Data Protection Regulation (GDPR).

    Home or Index page

    The following image shows the app after accepting tracking:

    Home or Index page

In the next part of this tutorial, you learn about MVC and start writing some code.