Just another asp.net MVC vs Web Forms

This might be a little bit boring, but I found a lot of developers cannot understand the basic concept on asp.net MVC. I think this is worth to talk about the basic of asp.net MVC.

On high level, you can create web page using asp.net web form or MVC to complete your task, it is transparent to user. However, adopting MVC might increase your productivity and increase your product quality. Gone are the day where you need to handle master page, ascx and aspx for every page that you work on.

Model View Controller, as the name implied, you do your build on 3 different layers.

Model → Handle data
View → Handle view
Controller → Handle logic

These seem logical so far. However, when I asked “Tell me the processing flow when you receive a request message from browser”, thing get confused.

How it works

  1. Request message enter into MVC via method calling in Controller, this is different from asp.net web forms where you are accessing a page. In MVC context, you are accessing a method in controller class
  2. The next question is which function to access, this depends on your routing table. It will pick the method name and controller class name that match the route condition.
  3. You have your business logic in controller and it will use model to pass the data for view to consume.
  4. Your view will have no ideal what’s happening in controller, it only follow the data in model to display the access.

In this high level flow, i skip the discussion on http handler, controller factory and filter. The above flow is very basic and you should know about it if you code MVC development.

Key benefits

  1. You will not see the funny tag like asp.net web form anymore.
  2. Better unit testing since it is method driven rather than page driven, this is extremely important when we are talking of CI/CD today.
  3. Decouple dependency on frontend and backend and the team can work on the task in parallel

Eventually MVC is still asp.net, so all authentication framework that you are familiar with are still applicable.

In short, there’s no reason you should not use MVC in your next application development. Visit Microsoft official website to find out more.