Prerequisites and Project Creation

Welcome to the setup guide for ASP.NET Core MVC. This module will walk you through the essential steps to get your development environment ready and create your first ASP.NET Core MVC project.

System Requirements

Before you begin, ensure you have the following installed:

  • .NET SDK: Download and install the latest stable version of the .NET SDK from the official .NET website. This includes the .NET runtime and essential development tools.
  • Code Editor: Visual Studio Code is recommended for its excellent support for C# and web development, but Visual Studio (Community, Professional, or Enterprise) or JetBrains Rider are also excellent choices.
  • Optional: Browser Developer Tools: Familiarity with your browser's developer tools (e.g., Chrome DevTools, Firefox Developer Tools) is highly beneficial for debugging.

Creating a New ASP.NET Core MVC Project

You can create a new ASP.NET Core MVC project using the .NET CLI or your IDE.

Using the .NET CLI:

Open your terminal or command prompt, navigate to the directory where you want to create your project, and run the following command:

dotnet new mvc -o MyFirstMvcApp

This command will:

  • dotnet new mvc: Use the 'mvc' template to create a new web application.
  • -o MyFirstMvcApp: Specify the output directory name for your project.

Using Visual Studio:

  1. Open Visual Studio.
  2. Click "Create a new project".
  3. Search for "ASP.NET Core Web App (Model-View-Controller)".
  4. Select the template and click "Next".
  5. Enter your project name (e.g., "MyFirstMvcApp") and location.
  6. Click "Create".
Important: Ensure that the correct .NET version is selected when creating the project. For this module, we recommend using the latest LTS (Long-Term Support) version.

Understanding the Project Structure

Once the project is created, you'll find a well-organized structure:

  • Controllers: Contains the logic for handling incoming requests and returning responses.
  • Models: Represents the data and business logic of your application.
  • Views: Responsible for rendering the user interface (HTML).
  • wwwroot: Contains static assets like CSS, JavaScript, and images.
  • Program.cs: The entry point of your application, responsible for bootstrapping.
  • Startup.cs (for .NET 5 and earlier) or configuration within Program.cs (for .NET 6+): Configures your application's services and request pipeline.
Tip: Familiarize yourself with this structure. It's the foundation of how MVC applications work.

Running Your Application

To run your newly created application:

  1. Navigate to your project directory in the terminal: cd MyFirstMvcApp
  2. Run the application: dotnet run

Your application will typically start at https://localhost:5001 or http://localhost:5000. Open this URL in your web browser to see the default ASP.NET Core MVC welcome page.

Congratulations! You have successfully set up your ASP.NET Core MVC project and are ready to start building dynamic web applications.