Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Get started with ASP.NET Core MVC

Feedback

In this article

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.

ByRick 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 theRazor Pages version of this tutorial, which provides an easier starting point. SeeChoose 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 selectCreate a new project.
  • In theCreate a new project dialog, selectASP.NET Core Web App (Model-View-Controller) >Next.
  • In theConfigure your new project dialog:
    • EnterMvcMovie forProject name. It's important to name the projectMvcMovie. Capitalization needs to match eachnamespace when code is copied.
    • TheLocation for the project can be set to anywhere.
  • SelectNext.
  • In theAdditional information dialog:
    • Select.NET 9.0 (Standard Term Support).
    • Verify thatDo not use top-level statements is unchecked.
  • SelectCreate.

Additional info dialog

For more information, including alternative approaches to create the project, seeCreate 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

  • PressCtrl+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?

    SelectYes if you trust the IIS Express SSL certificate.

    The following dialog is displayed:

    Security warning dialog

    SelectYes if you agree to trust the development certificate.

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

Visual Studio runs the app and opens the default browser.

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

Launching the app without debugging by pressingCtrl+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 theDebug menu:

Start Debug and Start Without Debugging menus

You can debug the app by selecting thehttps 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.

In the next tutorial in this series, 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 theRazor Pages version of this tutorial, which provides an easier starting point. SeeChoose 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 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 selectCreate a new project.
  • In theCreate a new project dialog, selectASP.NET Core Web App (Model-View-Controller) >Next.
  • In theConfigure your new project dialog:
    • EnterMvcMovie forProject name. It's important to name the projectMvcMovie. Capitalization needs to match eachnamespace when code is copied.
    • TheLocation for the project can be set to anywhere.
  • SelectNext.
  • In theAdditional information dialog:
    • Select.NET 8.0 (Long Term Support).
    • Verify thatDo not use top-level statements is unchecked.
  • SelectCreate.

Additional info dialog

For more information, including alternative approaches to create the project, seeCreate 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

  • PressCtrl+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?

    SelectYes if you trust the IIS Express SSL certificate.

    The following dialog is displayed:

    Security warning dialog

    SelectYes if you agree to trust the development certificate.

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

Visual Studio runs the app and opens the default browser.

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

Launching the app without debugging by pressingCtrl+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 theDebug menu:

Start Debug and Start Without Debugging menus

You can debug the app by selecting thehttps 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.

In the next tutorial in this series, 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 theRazor Pages version of this tutorial, which provides an easier starting point. SeeChoose 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 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 selectCreate a new project.
  • In theCreate a new project dialog, selectASP.NET Core Web App (Model-View-Controller) >Next.
  • In theConfigure your new project dialog:
    • EnterMvcMovie forProject name. It's important to name the projectMvcMovie. Capitalization needs to match eachnamespace when code is copied.
    • TheLocation for the project can be set to anywhere.
  • SelectNext.
  • In theAdditional information dialog:
    • Select.NET 7.0.
    • Verify thatDo not use top-level statements is unchecked.
  • SelectCreate.

Additional info dialog

For more information, including alternative approaches to create the project, seeCreate 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

  • PressCtrl+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?SelectYes if you trust the IIS Express SSL certificate.The following dialog is displayed:Security warning dialogSelectYes if you agree to trust the development certificate.For information on trusting the Firefox browser, seeFirefox SEC_ERROR_INADEQUATE_KEY_USAGE certificate error.

Visual Studio runs the app and opens the default browser.

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

Launching the app without debugging by pressingCtrl+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 theDebug menu:

Debug menu

You can debug the app by selecting thehttps 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.

In the next tutorial in this series, 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 theRazor Pages version of this tutorial, which provides an easier starting point. SeeChoose 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 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 selectCreate a new project.
  • In theCreate a new project dialog, selectASP.NET Core Web App (Model-View-Controller) >Next.
  • In theConfigure your new project dialog, enterMvcMovie forProject name. It's important to name the projectMvcMovie. Capitalization needs to match eachnamespace when code is copied.
  • SelectNext.
  • In theAdditional information dialog, select.NET 6.0 (Long-term support).
  • SelectCreate.

Additional info dialog

For alternative approaches to create the project, seeCreate 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

  • Select 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?

    SelectYes if you trust the IIS Express SSL certificate.

    The following dialog is displayed:

    Security warning dialog

    SelectYes if you agree to trust the development certificate.

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

Visual Studio runs the app and opens the default browser.

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

Launching the app without debugging by selecting 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 theDebug menu:

Debug menu

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

MvcMovie debug button

The following image shows the app:

Home or Index page

In the next tutorial in this series, 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 theRazor Pages version of this tutorial, which provides an easier starting point. SeeChoose 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 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 selectCreate a new project.
  • In theCreate a new project dialog, selectASP.NET Core Web Application >Next.
  • In theConfigure your new project dialog, enterMvcMovie forProject name. It's important to name the projectMvcMovie. Capitalization needs to match eachnamespace matches when code is copied.
  • SelectCreate.
  • In theCreate a new ASP.NET Core web application dialog, select:
    • .NET Core andASP.NET Core 5.0 in the dropdowns.
    • ASP.NET Core Web App (Model-View-Controller).
    • Create.

Create a new ASP.NET Core web application

For alternative approaches to create the project, seeCreate a new project in Visual Studio.

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

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

Run the app

  • Select 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?

    SelectYes if you trust the IIS Express SSL certificate.

    The following dialog is displayed:

    Security warning dialog

    SelectYes if you agree to trust the development certificate.

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

    Visual Studio:

    The address bar showslocalhost:port# and not something likeexample.com. The standard hostname for your local computer islocalhost. When Visual Studio creates a web project, a random port is used for the web server.

Launching the app without debugging by selecting 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 theDebug menu item:

Debug menu

You can debug the app by selecting theIIS 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 theRazor Pages version of this tutorial, which provides an easier starting point. SeeChoose 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 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

  • From the Visual Studio, selectCreate a new project.

  • SelectASP.NET Core Web Application >Next.

    Create a new ASP.NET Core Web Application project

  • Name the projectMvcMovie and selectCreate. It's important to name the projectMvcMovie so when you copy code, the namespace will match.

    Configure your new project

  • SelectWeb Application(Model-View-Controller). From the dropdown boxes, select.NET Core andASP.NET Core 3.1, then selectCreate.

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

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

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

Run the app

  • Select Ctrl+F5 to run the app without debugging.

    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?

    SelectYes if you trust the IIS Express SSL certificate.

    The following dialog is displayed:

    Security warning dialog

    SelectYes if you agree to trust the development certificate.

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

    Visual Studio:

    The address bar showslocalhost:port# and not something likeexample.com. The standard hostname for your local computer islocalhost. When Visual Studio creates a web project, a random port is used for the web server.

Launching the app without debugging by selecting 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 theDebug menu item:

Debug menu

You can debug the app by selecting theIIS 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.

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?