Learn About MVC Architecture

MVC is actually the architectural pattern for implementing UI, although it was originally developed for desktop applications in 1970s. But then it is widely adopted in Web applications as well. And then as a result many frameworks have been created to enforce this pattern. MVC architecture has been famous for a long time in software engineering. Many programming languages adopt this pattern with different variations. But here we’ll discuss MVC patterns in terms of ASP.NET.

MVC is actually the architectural pattern for implementing UI, although it was originally developed for desktop applications in 1970s. But then it was widely adopted in Web applications as well. As a result many frameworks have been created to enforce this pattern. MVC architecture has been famous for a long time in software engineering. Many programming languages adopt this pattern with different variations. But here we’ll discuss MVC patterns in terms of ASP.NET.

Model

Application data and behavior in terms of its problem domain are independent of UI. These classes have properties and methods that purely represent application state and rules. As we already know that the http protocol doesn’t maintain its state, it is actually stateless. But our model classes can maintain the state of the application. We’ll define it with an example later on.

Model class are used to enforce the validation logic and the business rules of the data. They are not tight to the UI which means we can take these classes and use them in a different kind of app such as a desktop or mobile app. They are plain old CLR objects (POCO)

What is POCO?

The plain empty classes which we create in our models folder are called POCO. They just have the data information (properties) to hold the data they don’t have persistence logic, they are actually persistent ignorant. Let’s suppose we have a model class.

  1. public class Student{}  

then it will not have methods like Student.Save() or Student.GetStudentByName() etc. POCO classes just hold the data and we apply validations here for different kinds of restrictions.

View

The Html markup that we display to the user.

Controller

Normally a user interacts with the view and performs some action on the screen. A request is generated from the view which is handled by the controller. Controller is actually responsible for handling http request. Suppose our application has been hosted on ‘localhost’ domain and when we send the request to

http://localhost:53456/students

a controller will be selected to handle this request. This controller will get all the students from the database and put them into the view and return the view to the client into the browser.

With this architecture, you can see each component has different SOC (Separation of Concern) and it makes the application more maintainable. Now there is 1 more piece to this architecture which is not in the acronym (MVC) - it’s the Router.

We’ve already discussed that when the request comes in then controller handles the request. But there are multiple controllers in the application and it is the responsibility of the Router to match the requested URL from their routes and request a right controller to handle that request.

ASP.NET

I think this above picture is self-explanatory regarding how ASP.NET application handles the request.

So it is also important to learn the routing as well. We’ll discuss the routers in detail in our next articles. Being a ASP.NET Web Developer, it is important to have a knowledge of MVC Framework because sometimes these kind of questions are the part of Interview question. Let me tell you what are the features released with MVC libraries, 

MVC VersionVisual Studio.Net VersionRelease dateFeatures
MVC 1.0VS2008.Net 3.513-Mar-2009
  • MVC architecture with webform engine
  • Routing
  • HTML Helpers
  • Ajax Helpers
  • Auto binding
MVC 2.0VS 2008,.Net 3.5/4.010-Mar-2010
  • Area
  • Asynchronous controller
  • Html helper methods with lambda expression
  • DataAnnotations attributes
  • Client side validation
  • Custom template
  • Scaffolding
MVC 3.0VS 2010.Net 4.013-Jan-2011
  • Unobtrusive javascript validation
  • Razor view engine
  • Global filters
  • Remote validation
  • Dependency resolver for IoC
  • ViewBag
MVC 4.0VS 2010 SP1,
VS 2012
.NET 4.0/4.515-Aug-2012
  • Mobile project template
  • Bundling and minification
  • Support for Windows Azure SDK
MVC 5.0VS 2013.NET 4.517-oct-2013
  • Authentication filters
  • Bootstrap support
  • New scaffolding items
  • ASP.Net Identity
MVC 5.2 - CurrentVS 2013.NET 4.528-Aug-2014
  • Attribute based routing
  • bug fixes and minor features update
 
Don't be worry about all these stuff that you need to keep in mind, I've mentioned these things here and now just watch these things before interview.