Introduction to ASP.NET Core MVC on macOS, Linux, or Windows
This tutorial will teach you the basics of building an ASP.NET Core MVC web app using Visual Studio Code (VS Code). The tutorial assumes familarity with VS Code. See Getting started with VS Code and Visual Studio Code help for more information.
This tutorial teaches ASP.NET Core MVC with controllers and views. Razor Pages is a new alternative in ASP.NET Core 2.0, a page-based programming model that makes building web UI easier and more productive. We recommend you try the Razor Pages tutorial before the MVC version. The Razor Pages tutorial:
- Is the preferred approach for new application development.
- Is easier to follow.
- Covers more features.
There are 3 versions of this tutorial:
- macOS: Create an ASP.NET Core MVC app with Visual Studio for Mac
- Windows: Create an ASP.NET Core MVC app with Visual Studio
- macOS, Linux, and Windows: Create an ASP.NET Core MVC app with Visual Studio Code
Install VS Code and .NET Core
Install the following:
Create a web app with dotnet
From a terminal, run the following commands:
mkdir MvcMovie cd MvcMovie dotnet new mvc
Open the MvcMovie folder in Visual Studio Code (VS Code) and select the Startup.cs file.
- Select Yes to the Warn message "Required assets to build and debug are missing from 'MvcMovie'. Add them?"
- Select Restore to the Info message "There are unresolved dependencies".
Press Debug (F5) to build and run the program.
VS Code starts the Kestrel web server and runs your app. Notice that the address bar shows
localhost:5000 and not something like
example.com. That's because
localhost is the standard hostname for your local computer.
The default template gives you working Home, About and Contact links. The browser image above doesn't show these links. Depending on the size of your browser, you might need to click the navigation icon to show them.
In the next part of this tutorial, we'll learn about MVC and start writing some code.