Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Targeting the Enterprise with ASP.NET MVC 2.0

The benefits of using an MVC Framework is that it helps enforce a clean separation between the models, views, and controllers within a Web application.


advertisement

ASP.NET MVC 2.0 is the latest Microsoft framework for building web applications on top of the .NET framework 2.0, 3.0, 3.5 etc.

MVC stands for Model, View, and Controller, a design pattern that is widely accepted throughout the development industry. You can download MVC 2.0 Beta from the following URL. http://www.microsoft.com/downloads/details.aspx?FamilyID=4817cdb2-88ea-4af4-a455-f06b4c90fd2c&displaylang=en



Microsoft has also published source code of the MVC Framework, which can be downloaded from Codeplex. http://aspnet.codeplex.com/releases/view/39978

For a little perspective, MVC Framework is a part of Visual Studio 2010 Beta 2, and this will be included with the VS 2010 final version as well, which will be launched in April. MVC 2.0 Framework is still a beta version and bug fixes are still in progress. Hopefully we will get the fully tested version very soon. A year ago, the ASP.NET MVC source code was released under the Microsoft Public License.

The Model, View, Controller Design Pattern

Model, View, Controller is an architectural approach to separate application business and model objects from the user interface. View is the output visible to the users. For an ASP.NET application it would be .ASPX, HTML pages, and controls embedded in these pages. View represents the look and feel of an application and totally isolates the business data processing.

The Model consists of actual data processing elements like all database related operations. The Model also feeds data to the View. It is designed in such a way that it can interact and pass data to many views and avoid code redundancy. Model responds to the request made by controllers and also notifies views to update their display with new data.

Controllers are responsible for triggers or actions. Controllers are nothing but events raised by users like mouse click, keyboard key press, etc. Most of the time, events are raised by users while interacting with the View. These triggers do make changes, calling methods defined in Model and update Model state. Model also notifies View to refresh its display.

HTTP request processing for ASP.NET and MVC applications are different. For MVC applications, HTTP requests are routed based on the route information stored in RouteTable object.

Creating an MVC 2.0 New Web Application

When you select New Project Option in the Visual Studio 2008 editor, the following popup comes up for selecting project type. If MVC 2.0 is installed in your machine, you will get two Project Types: 1) ASP.NET MVC 2 Web Application, and 2) ASP.NET MVC 2 empty Web Application. On the right side dropdown you can select .NET Framework Version, on top of which you want to execute your MVC Web Application.

Figure 1.Different MVC project templates.

For this example I have selected ASP.NET MVC 2 Web Application and .NET Framework 3.5.

On the next screen you will be asked to include Unit Test Project to your solution. Visual Studio Unit test Framework is included with MVC 2.0 framework and that would be the default selection. If you want to include a custom unit testing framework like Nunit, install the Library and locate the following registry key.


HKEY_LOCAL_MACHINE\SOFTWARE\VisualStudio\9.0\MVC\TestProjectTemplates

Under TestProjectTemplates, add the Template name like Nunit. Under the test framework, add a key for the code language, such as "C#" or "VB". Also add the following values under test framework. * AdditionalInfo -- This is optional. Enter a URL that links to a Web page about the test framework.
* Package -- This is optional. Enter the path of a Visual Studio 2008 package.
* Path -- Enter the path where the template is located. Generally its in %Program Files%\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates.
* Template -- name of the test template.
* TestFrameworkName - Enter the name of the test framework that will appear in the Test framework list.

Figure 2.Adding a Unit Test Project to your MVC applications.

Click Ok to Create MVC Test Project. Now you will be able to see two projects -- MVC main project and MVC test project under your main solution(MyMvcSample).

Figure 3.The folder structure of your MVC application.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap