Blue Theme Orange Theme Green Theme Red Theme
 
Click Here for 3 Month Free of ASP.NET Hosting!
Home | Forums | Videos | Photos | Downloads | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » ASP.NET MVC & JQuery » An Introductory look at the ASP.Net 3.5 Model-View-Controller Framework

An Introductory look at the ASP.Net 3.5 Model-View-Controller Framework

In this article we will take a brief look at the Model View Controller Framework extension for ASP.Net 3.5.

Author Rank:
Technologies: .NET 3.0 and 3.5, XAML,Visual C# .NET
Total downloads :
Total page views :  4277
Rating :
 5/5
This article has been rated :  2 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
Become a Sponsor




In this article we will take a brief look at the Model View Controller Framework extension for ASP.Net 3.5. We will explore the core concepts and key components of the architecture. We will touch on the advantages and limitations of the MVC framework and look at areas where it would be a fitting choice of architecture.

The Model-View-Controller pattern concept:

In the MVC design pattern, the application is split into the model, the view and the controller. The View corresponds to the visual presentation layer, the Model contains the entities/business objects and the Controller determines the application flow/user interaction.

ASP.Net MVC Framework

The ASP.Net MVC Framework is available as an Extension for ASP.Net 3.5.It's expected to be available as a part of a future release for ASP.Net 3.5. Note that MVC is not included in the recently released .Net 3.5 Service Pack Beta.

It offers an alternative to the Web Forms model in ASP.Net. The web forms model is page-centric and the page life-cycle and view-state are the driving criteria for the web forms model.

The MVC framework uses a Front Controller pattern - i.e. the controller determines the routing of URLs. Paths in the application do not necessarily have to correspond in a one-to-one manner to web pages.

URL Mapping Engine

The ASP.Net MVC framework uses URL Routing to map URLs to controllers and actions. URL Routing is performed by parsing the URL based on patterns and variables are passed to the controller as actions.

Default URL pattern is in the form {controller}/{action}/{id}
For example http://www.mySampleKB.net/HR/Benefits/Show/Leavepolicy

Server www.mySampleKB.net
Application HR
Controller Benefits

The URLRoutingModule object routes the URL Request first and then the MVCHandler Http Handler determines the controller to use and the action to be invoked. The MVC framework automatically parses the name of the controller parameter and invokes the controller that is named with the corresponding name and a suffix of Controller. In the above example, the BenefitsController would have been invoked.

So, in the MVC implementation, you do not need to have a physical URL named Leavepolicy.aspx. The URL Routing will allow you to specify the view to be invoked when the above URL is requested.

Compared to URL Re-writing:

URL Re-writing is a different implementation that is available in ASP.Net. It basically allows the user to request a user-friendly URL and re-directs the request to the actual URL in the application. In contrast, URL Routing does not perform a page redirect.

Developer Details

In order to use the MVC Framework, you would choose the corresponding template from the Visual Studio project templates. You also get a choice to select the test framework.

You would specify the routing mappings and also any defaults for the routing, any constraints for the URLs that are to be supported in the application. You can specify URL paths of unknown depth by marking the parameter with *

Controllers

The ASP.NET MVC framework maps URLs to classes that are referred to as controllers. Controller classes process incoming requests, handle user input and interactions, and execute appropriate application logic. A controller class typically calls a separate view component to generate the HTML markup for the request.

A controller class must implement the System.Web.MVC.IController interface. All public methods are exposed as Actions. If you have a method that should not be exposed as an Action, it needs to be marked with the NonActionAttribute attribute.

View

The View component is responsible for the visual presentation layer in the application. By default, the MVC framework allows using the existing ASP.NET page (.aspx), master page (.master), and user control (.ascx) types for this purpose. When a request is made, first the controller class is selected and the action is determined. The action method along with the incoming parameter value is used to execute business layer code and select a view that renders a response to the user by calling the RenderView method Views should not contain any business logic implementation or data retrieval code.

Model

Model objects are the components that encapsulate business logic and typically handle the path between the database and View component. Model classes are typically stored in the Models subdirectory in the application. Model objects are instantiated by the Controller class

Advantages of the MVC Framework
  • Extensible, plug and play architecture - the components of the application are inherently compartmentalized making it easier to replace a component.
  • Enables the application to be "testable" and lends to the Test-Driven-development model.
  • URL mapping framework results in user-friendly URLs without the file-name extension required. Search Engine Optimization.
  • Supports majority of the ASP.Net features and allows using markup in existing ASP.Net pages/user controls/master pages
Limitations
  • Viewstate is not provided by the framework.
  • Learning curve
When would I use it?

Not all the time. Not a direct replacement for web forms
  • If you have no viewstate requirements or very little viewstate.
  • If you need user-friendly URLs
  • If you need to establish Search-engine optimization
  • E.g. Product Catalog, People Search
Links/References
MVC

Summary

In this article we explored the core concepts in the ASP.net MVC Framework. We have seen the various components and architecture involved in MVC applications and areas where the MVC framework would be a natural selection. With a multitude of technologies available, it may not be possible to have a hands-on for every technology being released but it helps to be in the know regarding the various options available so you can make the right choice at the right time. If you feel the MVC framework is an apt choice for your solution, the next step would be to try out sample applications using the MVC framework.


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Dipal Choksi
Dipal Choksi has over 10 years of industry experience in team-effort projects and also as an individual contributor. She has been working on the .Net platform since the beta releases of .Net 1.0.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved