Wednesday, 18 November 2015

ASP.net MVC for Beginners Guide

             In this article I'm going to explain what is MVC? Already Webforms fulfill my requirement why we go for MVC? What are all the disadvantages of using ASP.net Web Application and what are all the advantages of using ASP.net MVC. What type of Architecture we followed in MVC Patterns etc.

ASP.net MVC for Beginners guide:

Summary:


            In this article I'm going to explain what is MVC? Already Webforms fulfill my requirement why we go for MVC? What are all the disadvantages of using ASP.net Web Application and what are all the advantages of using ASP.net MVC. What type of Architecture we followed in MVC Patterns etc.
 
 

Content :

  • Introduction
  • ASP.net Vs MVC Vs Webforms
  • Problems with ASP.net Webforms
  • what's the Solution
  • ASP.net MVC Architecture
  • Conclusion

Introduction :


            We all know that ASP.net Webforms are ruling the world past 10-15 years onwards. Then why we are going with ASP.net MVC already ASP.net Webforms fulfill my requirement. What are all the disadvantages of using ASP.net WebForms.? What are all the advantages of using ASP.net MVC.?  
 
             In this article I'm going to explain detailed as of my knowledge and guidance of Mr. Sivaprasad Koirala.
  

ASP.net Vs MVC Vs Webforms:


              Don't think that MVC is different technology, as we are ASP.net Webform developers we all know that for some reasons we are maintain different architecture in real time, mostly we prefer 3-Tier architecture. Assume that MVC also one of the great architectural pattern to arrange our code in better way.
 
 

Problems with ASP.net Webforms

           In above point we concluded that there is no difference between ASP.net Webforms and ASP.net MVC except the structure, then why Microsoft Introduces ASP.net MVC.?
The main problem of ASP.net Webforms is Performance. There are 2 main reasons behind this. 
  • Response time: How fast the server responds to request?
  • Bandwidth Consumption: How much data is sent?

Response time issue's :

 
        I will give you small example how the Server respond to request. Drag and drop a textbox control in designer of ASPX page.   
 <asp:TextBox ID="txt1" runat="server"/>  

Assign value to that textbox control.
 Protected void Page_Load(object sender, EventArgs e)  
 {  
      txt1.Text="Hello";  
 }  
 

Execute the above program and see the output; and press F12 to view source of that result. It is something like HTML format output. 
 
          The final outputs we are generating is HTML format, then instead of creating server control and assign value to that in server side and generate HTML result directly why can't we create HTML Controls? Is it tough job to create HTML controls?
 
           For simple Textbox controls, server response is slow as compare to HTML control. Then how it is differ when we are using grids and some tree level structured controls?
 
Solution for the above issue : Work with Pure HTML controls.

 

Bandwidth Consuption:


          We all know that to maintain state to controls ASP.net provides different approaches to maintain state, one of that is ViewState(client side state management). In our real time project most of us are using ViewState and we know that it's store data in Page itself for every request. But we don't know the size of that.
 
If you are thinking about performance, then how viewstate give better performance when it's store the data in page.
 
Solution for the above issue : Get the RID of server controls.

 
Note : apart from the above 2 major issues, few minor issues which have cropped up due to the presence of code behind and server controls.
 


  • HTML Customization
  • Reusability of Code behind
  • Unit Testing
 
 

What's the Solution :


           Until now we discuss the problems of ASP.net Webforms the main problem of using this Performance and the root cause of this is "Server Controls and Code behind".
 
The solution for this is we need to move the code behind to separate class library and replace server controls with HTML Controls.

In simple way we can say that MVC is light weight where as Webforms are heavy weight.

 

ASP.net MVC Architecture :


           As we are a webform developers, if you look at the current architecture most of them are using 3-Tier architecture. i.e. UI Layer, Business Layer / Middle Layer, DataAccess Layer. We can club the UI and Middle layer into MVC i.e. Model handles middle layer i.e. Business Logic and View handles the UI i.e. ASPX and Controller will handles the code behind and DataAccessLayer is for retrieve data from database.



Conclusion :


I hope this article will give you brief description about What is MVC and how it is differentiate with webforms.