Learn ASP.NET MVC Step By Step For Beginners- Part One

Introduction

First of all, let me make it clear that ASP.NET MVC is not replacing ASP.NET Web Forms. Both these development models exist and can be used to develop ASP.NET Applications. ASP.NET MVC app is a more highly testable application than traditional ASP.NET Web form applications.

Why ASP.NET MVC when we have ASP.NET Web Forms?

ASP.Net

Let's understand the MVC architecture in ASP.NET.

MVC stands for Model, View and Controller. MVC separates an application into three components - Model, View and Controller. MVC was first invented by Trygve Reenskaug.

Model

Model represents the shape of the data and business logic. It maintains the data of the Application. Model objects retrieve and store the model state in a database.

View

View is a user interface. View displays the data, using model to the user and also enables them to modify the data.

Controller

Controller handles the user requests. Typically, the user interacts with the View, which in turn raises an appropriate URL request. This request will be handled by a controller. The controller renders the appropriate view with the model data as a response.

The flow of the user's request in ASP.NET MVC.

ASP.Net

  1. The user accesses the Web pages by entering a URL in the Browser.
  2. Request reaches Routing Engine of ASP.NET MVC.
  3. Based on the URL, Routing Engine selects a particular controller. If the user has typed www.Google.com/Videos, routing engine would control by the name Videos. Each controller is responsible for receiving the request and orchestrating with model and view to deliver the appropriate response.
  4. Based on user request, controller talks to model to apply the business rules and get the data.
  5. Controller gets the appropriate view for the request.
  6. Controller returns the view. The Web Server responds to the Browser with the generated HTML page.

Routing Engine in ASP.NET MVC

ASP.NET MVC routing is nothing but matching incoming URL to action.

ASP.Net

Every MVC Application must configure at least one route, which is configured by MVC framework by default. You can register a route in RouteConfig class, which is in RouteConfig.cs under App_Start folder.

Route registration process.

Run Application - Global.aspx - RouteConfig.cs

Point to Remember

Route must be registered in an Application_Start event in Global.ascx.cs file.

I hope you liked it. Thanks.

Ebook Download
View all
Learn
View all