web analytics

Building an ASP.NET Core MVC Web Application with Visual Studio

Options

codeling 1602 - 6666
@2020-11-21 14:15:02

In this topic, you'll learn the skills and tips to build an ASP.NET Core MVC web application using Visual Studio 2019.

Microsoft ASP.NET Core MVC is a programming model that you can use to create powerful and complex web applications. This model is based on the Model-View-Controller (MVC) architectural pattern which separates an app into three main components: Model, View, and Controller.

The MVC pattern helps you create apps that separate the different aspects of the app (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The pattern specifies where each kind of logic should be located in the app. The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. This separation helps you manage complexity when you build an app, because it enables you to work on one aspect of the implementation at a time without impacting the code of another. For example, you can work on the view code without depending on the business logic code. MVC-based apps contain:

  • Models: Classes that represent the data of the app. The model classes use validation logic to enforce business rules for that data. Typically, model objects retrieve and store model state in a database. In this tutorial, a Movie model retrieves movie data from a database, provides it to the view or updates it. Updated data is written to a database.

  • Views: Views are the components that display the app's user interface (UI). Generally, this UI displays the model data.

  • Controllers: Classes that handle browser requests. They retrieve model data and call view templates that return a response. In an MVC app, the view only displays information; the controller handles and responds to user input and interaction. For example, the controller handles route data and query-string values, and passes these values to the model. The model might use these values to query the database. For example, https://localhost:5001/Home/Privacy has route data of Home (the controller) and Privacy (the action method to call on the home controller). https://localhost:5001/Movies/Edit/5 is a request to edit the movie with ID=5 using the movie controller.

@2020-11-21 14:18:03

Firstly, you need to make sure you have the following version of software and SDKs installed:

If not, you have to upgrade to or install the latest version.

@2020-11-21 15:18:16

To create your first ASP.NET Core MVC web app

  1. tart Visual Studio and select Create a new project.
  2. In the Create a new project dialog, select ASP.NET Core Web Application > Next.
  3. In the Configure your new project dialog, enter MyFirstMvcWebApp for Project name. It's important to use this exact name including capitalization, so each namespace matches when code is copied.

  4. Select Create.
  5. In the Create a new ASP.NET Core web application dialog, select:
    1. .NET Core and ASP.NET Core 5.0 in the dropdowns.
    2. ASP.NET Core Web App (Model-View-Controller).
    3. Create

Create a new ASP.NET Core web application

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com