Introduction

This article explains the basics of ASP.NET MVC and explains the main advantages, version history, and environment setup and folder structures. Here, we can learn how to start first ASP.NET MVC application.

Read the next part of this article after reading this one,

What is ASP.NET MVC

MVC is an architectural pattern. It separates the application into three main components. The three compounds are Model, View, and Controller. It handles specific development aspects of an application. MVC is the most frequently used industry-standard web development framework.

Model

Getting Started with ASP.NET MVC

Model is a simple class. It is the shape of the data. The model contains business logic. Controller and View can access the model. The model helps to pass the data from the controller to view and view to the controller. Using the model we are displaying data in the view page.

View

Getting Started with ASP.NET MVC

The view is a user interface. It is used to display the entire data using the model. We are using two type of view engines in view. One is the traditional view engine and another one is the Razor view engine. Traditional view engine is normal “.ASPX” page.

Razor view engine is used to develop a normal page design using HTML Helper controls. It contains “.CSHTML” extension. A syntax-wise little bit different in both view engines.

Controller

Getting Started with ASP.NET MVC

The controller is the heart of MVC and it handles the user request. It is a simple class. The controller can access the model and pass data to view with the help of a model. We can pass the data between the controller and view using View Data, Temp Data, and View Bag. The controller is intermediate between model and view.

Model-View-Controller

Getting Started with ASP.NET MVC

Basic Work Flow of MVC

Getting Started with ASP.NET MVC

MVC workflow starts with the user’s request. Based on the request, first, it goes the controller then goes to the corresponding action method. In the action method, we are calling all layers like business logic layer and data access layer.

Once we reach action method then it goes to the Data access layer. Sometimes while requesting, the request contains some input data that binds with the model, then goes to the data access layer.

Request reaches data access layer then goes to the corresponding database. It fetches the data from a database based on the request then goes back to the reverse format. After fetching data and binding in the model it goes to the action method.

Action method returns the result to the corresponding view with the help of model . Now, the user gets the response. Action method returns results in a different format.

Advantages of MVC

Is MVC Replacing ASP.NET Web Forms?

No, MVC is not replacing ASP.NET web forms. It is another choice for developers to use. Many companies are still using the traditional ASP.NET web form. MVC is now used by many companies and it is very famous. It's based on the customer opinion and project structure, whether they use the traditional ASP.NET application or ASP.NET MVC.

Folder Structure of MVC

We can see the basic folder structure of MVC in the below screenshot. We can find the Model, View, and Controller in the below screenshot while opening ASP.NET MVC application, by default it contains Model, View, and Controller.

Getting Started with ASP.NET MVC

Environment Setup for ASP.NET MVC

Visual Studio 2017 is the latest version of Visual Studio. It supports all versions of ASP.NET MVC and ASP.NET MVC Core. We can install Visual Studio 2017 and create a web application using ASP.NET MVC. We can install Visual Studio 2017 with the following step by step article link.

First ASP.NET MVC Application

Step 1

Open Visual Studio 2017, Go to File - New - Project. Select Web - ASP.NET Web Application (.NET Framework). Give the Project a name and click ok.

Getting Started with ASP.NET MVC

Step 2

Select MVC in the template window and click ok. Once we click on MVC we can see the description on the right side as in the below screenshot.

Getting Started with ASP.NET MVC

Step 3

We can see that the folder structure looks like the below screenshot. We can find the Model-View-Controller architecture. The home controller is a default controller in the Controller folder. The home controller contains three action results.

  1. namespace FirstMVC.Controllers
  2. {
  3. public class HomeController : Controller
  4. {
  5. public ActionResult Index()
  6. {
  7. return View();
  8. }
  9. public ActionResult About()
  10. {
  11. ViewBag.Message = "Your application description page.";
  12. return View();
  13. }
  14. public ActionResult Contact()
  15. {
  16. ViewBag.Message = "Your contact page.";
  17. return View();
  18. }
  19. }
  20. }

Getting Started with ASP.NET MVC

Step 4

Build our ASP.NET MVC application, if build succeeeds then run the application. We can see it looks like the below screenshot.

Getting Started with ASP.NET MVC

Version History of MVC

Conclusion

This article explained how to start ASP.NET MVC, the basic idea of MVC, the workflow of MVC, and advantages of MVC. I hope this is very helpful for new learners.