Tuesday 15 July 2014

MVC 4 Introduction

Introduction

  • ASP.NET MVC 4 is a framework for building scalable, standards-based web applicationsusing well-established design patterns and the power of ASP.NET and the .NET Framework.
  • In this article I will give an introduction to ASP.NET MVC 4 from a beginner’s perspective.
  • This article is meant for all kind of beginner users who wanted to get started with ASP.NET MVC 4.
  • I have included a small comparison between ASP.NET MVC and ASP.NET Web forms for those who have already explored ASP.NET Web forms
  • Currently ASP.NET MVC 4 is supported in Visual Studio 2010 and Visual Studio 2012, previous versions of Visual Studio does not support ASP.NET MVC 4 as of now.
  • If you don’t have ASP.NET MVC 4 in your box then install MVC 4 for Visual Studio 2010 or else use Visual Studio 2012 to get started with this article .

What is ASP.NET MVC?

ASP.NET supports three different development models named Web Pages, MVC and Web Forms.
ASP.NET MVC is a web application development framework built on top of Microsoft’s .NET Framework. ASP.NET Web Form was a replacement for Microsoft’s Active Server Pages (ASP) but ASP.NET MVC is not a replacement for ASP.NET Web Forms and it’s just an alternate way of making an ASP.NET website.
ASP.NET MVC is open source!- In March 2012, Scott Guthrie announced on his blog that Microsoft had released part of their web stack (including ASP.NET MVC, Razor and Web API) under an open source license (Apache License 2.0).
Download from Codeplex.com

Why MVC?

ASP.NET MVC helps to reduce the complexity of the web application by dividing an application into three layers, Model, View and Controller. This separation (loose coupling) helps in some long term benefits like isolation of components while development and also this separation provides better support for test-driven development (TDD). ASP.NET MVCweb site are good in performance and also easy to maintain.

MVC Release History

The Current Version of ASP.NET MVC is 4 and it was released on 15th Aug 2012. ASP.NET MVC 4 is packaged with Visual Studio 2012 and MVC 4 can be installed for Visual Studio 2010. Below I have mentioned the release history of ASP.NET MVC.
​DATE ​VERSION
10 Dec 07 ​ ​ASP.NET MVC CTP
​13 Mar 09 ASP.NET MVC 1.0​
​16 Dec 09 ​ASP.NET MVC 2 RC
​04 Feb 10 ​ASP.NET MVC 2 RC 2
​10 Mar 10 ​ASP.NET MVC 2
​06 Oct 10 ​ASP.NET MVC 3 Beta
​09 Nov 10 ​ASP.NET MVC 3 RC
​10 Dec 10 ​ASP.NET MVC 3 RC 2
13 Jan 11​ ASP.NET MVC 3
​20 Sep 11 ASP.NET MVC 4 Developers Preview​
​15 Feb 12 ​ASP.NET MVC 4 Beta
​31 May 12 ​ASP.NET MVC 4 RC
​15 AUG 12 ​ASP.NET MVC 4
In this article we are discussing more about the latest version of MVC, that's MVC 4. Read more from Wikipedia onMVC Release History.
MVC Architecture
The Model-View-Controller (MVC) pattern is an architectural design principle that separates the application components of a Web application into three layers. This separation gives you more control over the individual parts of the application, which lets you more easily develop, modify, and test them.
Model contains and exposes the properties and application logic In a better way we can say that The model represents core business logic and data. In the ePhoneBook Sample the 'PhoneBookModel' class represents the properties of a “Phone Book” in the application and may expose properties such as First Name, Last Name and Mobile Number etc and also it may expose methods.
The View is responsible for creating the response HTML or any responses back to the browser like pdf, html or excel etc. In other way we can sat that the view is responsible for transforming a model or models into a visual representation.
Controller is responsible for processing user inputs from view and give responses back to the view. It means that the controller decides the action and performs the tasks/logic based on the parameters.Controller acts as the coordinator between the view and the model.

Comparing ASP.NET MVC with ASP.NET Web Forms

  • If you have already worked with ASP.NET Web forms then you might be interested to see some comparisons between these two.
  • The main thing is that both ASP.NET Web form and ASP.NET MVC are built on top of ASP.NET Framework.
  • There are some similarities and differences between these two.
  • ASP.NET Web forms web development is very easy compared to ASP.NET MVC apps. and Web forms doesn't require a developer to be an expert in JavaScript and HTML to write a web application but ASP.NET MVC is full of scripting technologies and it requires a good command over scripting technologies.
  • ASP.NET Web form is very rich with server controls but in ASP.NET MVC there are no server controls supported and its fully depend on HTML controls. If you look at the below image you can see that no server controls are present in the toolbox.

  • There is no View State in ASP.NET MVC. we can use HtmlHelpers in ASP.NET MVC for rendering HTML controls in a view.
  • ASP.NET MVC is based on Separation Of Concerns that's why ASP.NET MVC is pluggable and flexible system.
  • Implementing Test projects with ASP.NET MVC is simple than Web forms.
  • ASP.NET MVC request cycle is very simpler than Web forms and MVC gives a good performance.
  • In my opinion I feel for a Web form developer, ASP.NET MVC is difficult to learn and understand as its much into coding not much drag and drop but once its fully understood then its very easy.
  • Layout page is the Master page available in ASP.NET MVC and partial views can be considered as a replacement of user control in Web form.
  • Web form uses normal Web-form syntax where as MVC app uses customizable syntax default to Razor.
  • There are many more similarities and differences, Once you start writing code with ASP.NET MVC you will learn more.   

No comments:

Post a Comment