Introduction To MVC

Introduction

Model View Controller (MVC) is a software pattern that decouples various components of wen applications. The three main terms in MVC denotes:

  • Model: It basically denotes the domain data
  • View: It's basically the User Interface to render the domain data
  • Controller: It translates user action into the appropriate operation done on the model

So we can say that the ASP.Net MVC is a web development framework that is based on the MVC design pattern,


Figure 1: MVC


Figure 2: MVC Flow

Difference between ASP.Net MVC and Webform

Web forms use the page controller pattern whereas MVC uses the view controller approach. In a page controller every page has it's own page life cycle. In other words, it's own code behind file and process request. Whereas in MVC a common controller serves all page requests. Some more basic differences are:
  • Action based requirement
  • Reusability
  • Various type of return content (such as XML, HTML and JSON)
  • View and Data: combine data and return a view
  • Unit testing

Core Features of ASP.Net MVC

  • Clear separation between presentation between presentation and business logic layer
  • Extensible and Pluggable framework
  • Routing
  • Support existing ASP.Net features

Routing

The MVC framework uses user-friendly URL's, that more easily describe the user's action and these actions are not mapped to any physical file. MVC uses the routing engine that maps an URL to a Controller class. The Latest version of MVC is MVC 5.

Main MVC-5 Features

The following are the main features of MVC 5:

  • One ASP.Net
  • ASP.Net Identity
  • Bootstrap
  • Authentication filter
  • Filter overrides

One ASP.Net

A MVC application is now a standard web application and it doesn't use their own project GUID. It helps you to mix and match various technologies of your preferred app.

ASP.Net Identity

Used ASP.Net Identity can be used now for the Identity management.

Claim based Authentication: ASP.Net identity supports claim-based authentication in which the identity of any user is defined as a set of claims from a trusted issuer.

  1. ClaimsIdentity claimsIdentity = null;  
  2. var claim = new List<Claim>();  
  3. claim.Add(new Claim(ClaimTypes.Email, “[email protected]”));  
  4. claim.Add(new Claim(ClaimTypes.Sid, “101”));  
  5. claimsIdentity = new ClaimsIdentity(claim,  
  6. DefaultAuthenticationTypes.ApplicationCookie); 

If you want to authorize a request from a client application to your web API, it can be done using oAuth 2.0.

Authentication filter

These filters in ASP.Net MVC runs prior to an authorization filter of the ASP.Net MVC pipeline and also allows you to determine the authentication logic per action per controller.

Filter Override

In MVC the configuration of the filters can be allowed globally and can exclude certain global filters from applying to specific actions and controllers.

In a controller there are many actions we can do. The following is an introduction to the ActionResult and ViewResult classes.



Figure 3: MVC ActionResult and ViewResult

There are many types of response types that can be sent to end users, the following are some of them:

  • ViewResult
  • PartialViewResult
  • EmptyResult
  • RedirectResult
  • RedirecttoRouteResult
  • JSONResult
  • JAvaScriptResult
  • ContentResult
  • FileContentResult
  • FileStreamResult
  • FilePAthResult

Up Next
    Ebook Download
    View all
    Learn
    View all