I have seen so many developers frequently asking why we need ASP.NET MVC, or MVC architecture itself? . Why microsoft is giving so much importance to MVC?.
My humble answer would be Every Architecture or Programming Language would have it’s own advantages as well as disadvantages. MVC has a purpose, that’s why in programming world it’s so popular. Lazy developers who just want to drag and drop controls and double click on the visual editor and go to code behind and do the coding, would not be able to understand the need of MVC at first.
There would be lots of questions in mind that,
- why we need to use such an old framework(MVC was initially founded in early 70’s, Still rocking and not out)?.
-
It’s so difficult to develop, asp.net webforms are better?
Your doubts are all reasonable, if you are a small scale application developer and there only few people in team.
There is an article which i previously published “ASP.NET WebForms vs ASP.NET MVC” , if find time in reading it would provide much more clear idea on our discussion.
So new people, do not get confused between ASP.NET MVC and Webforms.
Webforms has these disadvantages
* Less Unit Testing Support
It’s teadious task to do unit testing on ASP.NET Webforms or pages, because web forms each and everything are wired up together. Testing one would need the other, to be more precise there is lots of events and we cannot do unit testing on a button click event etc and capture result etc. There are other 3rd party tools or frameworks which provides unit testing support, even though you will not be able to do a complete unit testing.
* Less SEO Friendly
All web applications are developed to meet with SEO standards. But ASP.NET WebForms would not provide SEO friendly urls.
* Less Managability
Think about your application is a big one. Nearly 30-50 members are in the team developing different forms. Suppose if a developer has not completed a form, the remaining developers who are writing the code for handling the result from the form would have to wait until the developer completes his functionalities in the page. or if the project has 100 or more pages or so, managing all these pages and maintenance would be troublesome.
Another scenario, How about UI Designer wouldwork on UI part and there will be a another developer for handling the code behind coding. So developer assigned to do the Code-Behind would have to wait until, the UI Designer finishes his work off.
When we work as team, it’s always better to split the tasks to one another and each of them would finish their tasks on time, with out have to wait for other developers to finish their works. With webforms such kind of project handling would be difficult. But webforms are good and easy.
- Components are depend on each other
In webforms one control will be depending on it’s parent or child controls and event wire up etc. Thus the forms is coupled with each and every component or control it is consuming or depending.
All the things lacking in web forms will be easy to implement using ASP.NET MVC.
* Unit Testing Support
MVC is mainly based on actions, which is specified in Controller. Model – View – Controller, all these components are loosely coupled, so that you can indiviually test the Model or View or Controller.
* SEO Friendly
MVC formulates SEO friendly URL’s
For Eg:
We have web application page for viewing customer information and the customer id has been passed to the page as a Query String. So the typical url will look like http://localhost/MyApp/ViewCustomer.aspx?id=3
Is not friendly to SEARCH ENGINE CRAWLERS or BOTS, which automatically travers through each website and extract the page information.
but MVC will provide much more effective REST(REpresentational State Transfer) based Urls.
So assume that in MVC the above Url would be represented like and the name of the customer is “JohnJoe”. Since we need to represent the Url by the resource name, here it is Customer Name.
http://localhost/MyApp/Customer/Johndoe
When the seach engine crawler comes in, it finds that the resource is “JohnDoe” and enlists the Url.
* Managability
Components in MVC are been developed individually, diving a large project among a team of 30-50 would be easy and developers would not have to wait until the other team members has finished they module or not. He will do his module, does the Unit Testing, captures the results and analyze and fixes if any error.
* Loosely coupled with components.
Model – View – Controller, all these components are loosely coupled, so that you can indiviually test the Model or View or Controller.
I hope this article gives a basic understanding on the importance of ASP.NET MVC, right now i am able to provide a very less information only, in future i may be able to provide more. If you have any concerns let me know through mail or Comments.
NOTE: I wrote this article from my understanding. If you find any information is erranious or, leading into confusion, please let me know and leave comments.
Discover more from Cloud Distilled ~ Nithin Mohan
Subscribe to get the latest posts sent to your email.
Crystal clear explanation. Though I’ve used MVC2, I’ve never wondered why we need it in the first place. Just took it as something “new” and hence to be used – for better support. Of course much of the logic you’ve discussed on tight coupling between UI and page behind logic is not a desirable way to code. You should be using patterns to increase Testability of your codes – at least a Facade to separate out your “Controller logic”
Thanks Anantharaman. That was interesting to know about Facade.