Introduction to ASP.NET MVC (C#) – Part 1

Vasanthmvp
Posted by in ASP.NET MVC category on for Beginner level | Points: 250 | Views : 5751 red flag
Rating: 5 out of 5  
 1 vote(s)

Let's start with a series of articles to learn, try to understand and dig more into ASP.NET MVC Framework. As part of it, I'm posting my first article.

Introduction


I wish you all a very Happy New Year to you & your family. I am glad to start my first article on New Year. In this tutorial series, we are going to understand all about ASP.NET MVC.

Objective


Let’s begin here to bring you a lucid picture on what is MVC, why this came into picture, what are the advantages of MVC, will this be advantageous and how different is this over the existing system, etc., Good, if you already know this. If not, I hope you would become thorough once after going through this article.

Description:


Before we step in to our ASP.NET MVC, let me clear out the lice poking your mind. Straight to the point,
What are the pitfalls in the existing system ASP.NET Web Forms, which led us to pave our way to ASP.NET MVC framework.

On Comparing with ASP.NET Web Forms

The traditional ASP.NET works everything fine but it is more complicated in reality. Overtime, in the Web Forms some of the aspects were highlighted as shortcomings like:  
 
1. View State Weight: View State is nothing but a mechanism to maintain a state across the page requests. It results in a large chunk of data to be transferring between the client and server to maintain its state across requests. Sometimes, it may cross-high amount of KB’s. It goes back and forth with each request. Thereby, it shows a poor response on the page request as well as consumes more bandwidth. 
 
2. Page Life Cycle: As part of the Page life cycle, the mechanism for connecting client-side events with server-side event handler code would be much more complicated to deal at runtime without getting any view state errors. Some may even fail to execute.

3. False sense of Separation Of Concerns: Though ASP.NET’s code behind class separates the application code from User Interface HTML mark up, developers are encouraged to mix the presentation code(server side control like GridView) and the logic(Data from the database) within the code behind classes, which can be fragile and intelligible.

4. Limited Control over HTML: Though the Browser’s are compliant with HTML standards and render the server controls as HTML web controls, sometimes it would be tricky to get the HTML we expect. Prior to ASP.NET 4, the HTML output typically fails to comply with web standards or make good use of CSS and even sometimes generates an unpredictable and a complex id value, which are hard to access using JavaScript. These pitfalls are reduced in ASP.NET 4.
 

5. Leaky Abstraction: Web forms tries to hide away HTML and HTTP wherever possible. As you try to implement customer behaviors, you fall out of the abstraction, which forces you to reverse engineer the post back event mechanism or take obtuse acts to generate the desired HTML. wherever possible. As you try to implement customer behaviors, you fall out of the abstraction, which forces you to reverse engineer the post back
event mechanism or take obtuse acts to generate the desired HTML. Indeed ASP.NET abstracts away the difference between writing the HTML code to handle clicking on a hyperlink (<a>) and the code to handle clicking on a
button. Problem: the ASP.NET designers needed to hide the fact that in HTML, there’s no way to submit a form from a hyperlink. They do this by generating a few lines of JavaScript and attaching an onclick handler to the hyperlink. The abstraction leaks, though. If the end-user has JavaScript disabled, the ASP.NET application doesn’t work correctly, and if the programmer doesn’t understand what ASP.NET was abstracting away, they simply won’t have any clue what is wrong. (From http://www.onenaught.com/posts/42/aspnet-is-a-leaky-abstraction)

6. Low Testability: Unit testing being the essential part of any software development, the tightly coupled web forms architecture stands unsuitable for prefect Unit Testing.
 

Introduction & Advantage’s


  Model-View-Controller(MVC) is an architectural pattern.
  ASP.NET MVC is a web development framework that combines the effectiveness of classic ASP.NET along with MVC   architectural pattern.

1. It gives you a powerful, patterns-based way to build dynamic websites that enables “separation of concerns” to manage complexity.

2. It includes the best parts of existing ASP.NET and the most suitable for up-to-date techniques from “Agile Development” providing full control over application behavior for large teams.

3. Emphasizing, it enables fast Isolated TDD (Test Driven Development) which declares it as a best alternative to Web Forms pattern for creating MVC based web applications. Hence, ASP.NET MVC Framework can be titled highly testable presentation framework

4. No concept of “ViewState” or Server based forms. All the server side         controls of UI can be replaced by simple HTML. No need of using viewState, postback’s to create the effect of state fullness.  Hence, ASP.NET MVC Framework is called light weight.

5. It uses a Front Controller pattern that processes Web application requests through a single controller that provides you a rich routing infrastructure.

6. Defined in the fundamental supported part of ASP.NET’s System.Web namespace – System.Web.MVC

7. Can be easily replaced or customized, extensible and pluggable framework. The Framework is built as a series of independent components – as a .NET interface or built on an abstract base class, so you can easily replace or plug in your URL Routing System, your own View Engine, Controller factory, etc.,
You can use the default implementation of the component, OR
Derive a subclass to include its behavior OR
Change the component entirely with a new implementation of the interface or the base class. Similar to Provider model of ASP.NET 2.0

8. Tight Control over HTML and HTTP --> ASP.NET MVC recognizes the importance of producing clean, standards-compliant markup. Its built-in HTML helper methods produce standards-compliant output. For complicated UI’s, readymade widgets or libraries can be used. Hence, it is so well compatible with the popular JQuery library and Microsoft does provides jQuery as a built in part of the default ASP.NET MVC template and lets you directly reference jQuery.js file on Microsoft’s CDN (Content Delivery Network)  Servers.

9. It gives a powerful Routing System and User Friendly URL naming patterns for both Search Engine Optimization (SEO), Representational State transfer (REST) and are user readable. URLs do not need to include file-name extensions.

10. Modern API and ASP.NET MVC is open source. You can free to edit and compile your own version. You can download it from http://aspnet.codeplex.com/

Conclusion


So, I hope this article is helpful. In the further articles, we will see how the MVC framework looks like and its application structure, walkthrough of its evolution & up gradation including new features from its beta version, When to choose MVC pattern,etc.,

Reference


http://www.asp.net/mvc

Page copy protected against web site content infringement by Copyscape

About the Author

Vasanthmvp
Full Name: VASANTH KUMAR
Member Level:
Member Status: Member
Member Since: 6/26/2012 12:13:54 AM
Country: India
Awesome Coding !! :)
http://www.dotnetfunda.com
Started my journey with what is .Net on 30-07-2012 and pretty excited to learn & share it on DotNetFunda since 15-08-2012. :) Exploring more & more :)

Login to vote for this post.

Comments or Responses

Posted by: Saratvaddilli on: 1/1/2013 | Points: 25
nice article vasanth
Posted by: Vasanthmvp on: 1/6/2013 | Points: 25
Thanks Sarath.

Login to post response

Comment using Facebook(Author doesn't get notification)