Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Asp.Net Webforms vs ASP.Net MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 505
    Comment on it

    Asp.Net MVC is currently used and much embraced architecture in software development. It offers a layered approach to development by it's default configuration, and facilitates unit testing also.

    I've been working on web forms from the beginning of my career and except some hiccups, they have been very good friends of mine so far. There are benefits like easy mapping of server controls to HTML provided by designer, an event driven model of development and almost no special learning required for the architecture part.

    We can implement layered architecture in web forms too, so why MVC? Following are some of the reasons of using MVC (as per my experience and understanding):-

    1. Back to the Roots:- MVC is based on pure HTML page unlike server pages (.aspx) concept of web forms. So we save one conversion cycle from server controls or markup to html markup.
    2. All HTML:- MVC has only HTML controls. So you have the power to modify any of the controls in desired way using style sheets. Obviously one can not work with HTML controls and Markup for a large E-Commerce website so you have HTML Helpers for generating desired elements using code.
    3. Get Only What's Required:- In MVC the request calls the method of controller ('How' part explained in subsequent articles) and not the entire page like web forms. So you call the method which is required to fulfill the request, not the page which is obviously not required. So here we save another bandwidth consumption.
    4. Convention Over Configuration:- ASP.Net MVC follows convention over configuration approach in which you get a project architecture which is well defined for a jump start. You get a well built architecture with all folders in place and naming conventions are predefined. E.g. - When you create a controller you get the name with a suffix "Controller" which is mapped in route config and understood as a controller. And that is not strict. You can have your own name by implementing IcontrollerFactory interface and calling ControllerBuilder.Current.SetControllerFactory in Application_Start Method in Global.asax (Don't bother much about these details though. These are just to show that Convention over Configuration doesn't mean "Restriction" of any kind).
    5. Faster Execution, Better Performance:- Like we said above, we save a number of round trips by using MVC architecture. So MVC is fast as compared to webforms in performance (obviously, if implemented in right manner, true for both).
    6. Viewstate Gone!:- If viewstate is your best friend, you can face performance issues if project size grows. This is the most cunning villain in webforms development which seems to be friend of yours but hinders performance due to large encrypted values passed during postback.

    MVC Developer- Thankfully we've no viewstate in MVC.

    Web Forms Developer- What? How am I going to keep the values between postbacks?

    MVC Developer- Listen kid, you don't have the thing called "Postback" too.

    Web Forms Developer- The hell. I think I am done with MVC. I am good with webforms.

    MVC Developer- Hey Stop. That's what I was trying to tell you. We've got the controller. Once the values are in controller it's up to you. It's just like a viewstate.

    Web Forms Developer- Ok. And what about my beloved postback which used to post data to server in a seamless way?

    MVC Developer- You got the actual thing in MVC. You've got HTTP POST here which is the actual power behind your beloved "postback" and that too you can do in controller. So you prevented a variable and large value here to be sent on the network.

    Web Forms Developer- Hmm. That makes sense. Means we're getting everything in it's actual form in MVC rather than wrapped in events and variables like in web forms.

    MVC Developer- Now you are getting it right.


    1. jQuery!jQuery:- With MVC you've jQuery and many js libraries built in when you select MVC project(not empty one). And you can enjoy a seamless integration with many js libraries like Angular.js,Node.js,Dynamic.js,Knockout.js and so on.
    2. Cleanliness Everywhere:- You have cleanliness every where when you create a project in MVC. From separation in code to clean URLs ,you don't get clutter anywhere. URLs are clean due to routing and they are readable. Separation by convention provides a clean architecture to work with.

    More reasons are there to convince you to switch to MVC framework. Please suggest more if you come across more scenarios.

    Now what about webforms. Are they useless now? Definitely not. In some scenarios, webforms can be better, like:-

    1. Smaller projects:- MVC is best in every scenario in performance, but for small projects like dynamic website or small E-Commerce websites, MVC may not be feasible as compared to webforms. Because creating an MVC architecture well suited to the project may take equal time in which you can actuially complete the whole project in web forms!
    2. Simple in Learning:- In a scenario where you do not have time to arrange an MVC training for your developers and project is not strictly requiring MVC, web forms are a better choice as they are simple to learn.
    3. Tried and Trusted:- Web forms are tried and trusted and MVC is still in development. So if performance and maintainence is not a concern, use webforms as you can get lot of resources, rich control libraries for it. You can do the development on your own using webforms but MVC implies separation of concern and this reflects in team hierarchy too.

    So what's the verdict? If you ask me, I choose to stick to the performance part and will go with MVC!

    Thank You.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: