Blue Theme Orange Theme Green Theme Red Theme
 
DevExpress Free UI Controls
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » ASP.NET MVC & JQuery » ASP.NET 3.5 MVC Application

ASP.NET 3.5 MVC Application

This post gives you the basic overview on ASP.NET Models, Views and Controllers. It explains how all parts in MVC Application work together and discuss how the architecture of an ASP.NET MVC application differs from an ASP.NET Web Forms application.

Page Views : 43899
Downloads : 0
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Introduction

This post gives you the basic overview on ASP.NET Models, Views and Controllers. It explains how all parts in MVC Application work together and discuss how the Architecture of an ASP.NET MVC application differs from an ASP.NET Web Forms application.

The Sample ASP.NET MVC Application

  1. Launch Visual Studio 2008, Select the menu option File, New Project  then New Project Dialogue box appear as shown below

    mvc1.gif

    Select the ASP.NET MVC Web Application Template from the dialogue box and click Ok.

  2. When you create a ASP.NET MVC Application, Create Unit Test Dialogue box appears as shown below.

    mvc2.gif

    Select the No, do not create a unit test project and click Ok.

  3. After ASP.NET MVC Application is created. You will see several folders in Solution Explorer. You will find three folders named Models, Views and Controllers.

    mvc3.gif

    If you expand the Controllers Folder, you will see a file named HomeController.cs and if you expand the Views folder you will see About.aspx and Index.aspx under Home Sub Folder.

  4. Now you run the application you will see the following output

    mvc4.gif
Notice the URL in the  Address bar, When you click the Home menu link, The URL in the browser changes to /Home and when you click the About menu link, the URL changes to /About.

If you return to Visual Studio project you do not find the Home or About page.

A URL Does not Equal to a page in the application
  • When you build a ASP.NET Web Application, there is a correspondence between a URL and Page. If you request a page test.aspx from the server then page must be on the disk other wise 404 - page not found error will come.
  • When you build a ASP.NET MVC Application, there is no correspondence between URL and page that you found on the disk. Here a URL corresponds to a controller action instead of a page on the disk.
  • In ASP.NET Web Application, Requests are mapped to pages. In ASP.NET MVC Application ,request are mapped to controller actions.
  • ASP.NET Web Application is content-centric and MVC Application is logic centric.
URL Routing
  • Here Browser Request is mapped to controller action through a feature called URL Routing. URL Routing route the incoming requests to controller actions.
  • URL Routing uses Route Table that will be created when application first starts.
  • Route table is setup in the Global.asax file.

    The Default Global.asax file looks like

    mvc5.gif

    When ASP.NET Application first starts, the Application_Start() method is called. This method calls the RegisterRoutes() method which creates the default route table.
  • Route table breaks the incoming request into 3 parts
  • First part is mapped to a controller name, the second part is mapped to an action name and final part is a parameter that passed to the action.

    Example:  /Student/Details/3
    This URL is parsed into three parts like this:
    Controller = StudentController
    Action = Details
    Id = 3

    If you run the sample ASP.NET MVC Application with out supplying a URL, the URL is parsed like this

    Controller = HomeController
    Action = Index
    Id = ""
Controllers

A Controller is responsible for sending  the response back to a user who makes the request. Controller is just a C# class file. The Sample MVC Application contains the controller named HomeController.cs located in the Controllers folder.

The Controller in the ASP.NET  MVC Application looks like

mvc6.gif
 
Note: The two methods in the controller Index() and About() corresponds to two actions Home and About clicks.

Views
  • A view in the ASP.NET MVC Application contains the HTML elements and content that is sent to the browser.
  • The two actions in the controller return a view.
  • A View is equivalent to a page in ASP.NET MVC Application.
The HomeController.Index() action returns a view located in the following path

\Views\Home\Index.aspx

If you want to return a view for a controller action, you need to create a sub folder in the Views folder same name as controller and create a .aspx file with same name as the action.

Models

A Model in ASP.NET MVC Application contains logic that is not in the view or a controller. The Model should contain your business logic and Data access logic.
 
Conclusion

We had a overview on ASP.NET MVC application and URL Routing. We learnt the functionality of Model, Controller and View in the ASP.NET MVC Application.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Kalyan Bandarupalli
My name is Kalyan Bandarupalli and I currently live and work in London, UK. I was born in 1980 and i got my first computer when am studying my graduation. I am graduate in Computer Applications and I have done my masters degree in Information Systems. My Professional career started as software engineer and then senior software developer and Software Architect. I am Microsoft Tetchier use .NET technologies to develop the applications. Since 2003 i am working as .NET Developer.
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.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
Good reading by Mahesh On October 3, 2008
Good article Kalyan. Wonder what is the advantage of using MVC over traditional n-layer projects?
Reply | Email | Modify 
Re: Good reading by Kalyan On January 19, 2009

Hi Mahesh

layer oriented designed applications" do you mean an n-Tier architecture? If so, I think its important to point out that MVC is actually a design pattern primarily for your UI. If not, would you mind clarifying?

Typically one of the tiers in your n-Tier architecture is a presentation layer and below that you have an application (service) layer, right? MVC is a pattern that defines when, where, and how you should separate those two layers and, actually, how to further break-up the presentation layer itself.

Further down the line you have your domain (data) and infrastructure layers, but those are unaffected by the choice to use MVC and have other patterns (such as SOA) that you can use to help design those layers.

I know you asked for an explanation of some advantages, but I'm trying to clarify that MVC is in fact a METHOD of layering an application, not an alternative to it. If you'd like more information, please don't hesitate to ask

Reply | Email | Modify 
Re: Re: Good reading by mandava98 On January 8, 2010
I can't see "ASP.NET MVC Application" in my Visual Studio 2008. How to get it?

Thanks,

Sreeni
Reply | Email | Modify 
Good Article by NageshwarRao On October 7, 2008
Hi Kalyan, Its good. Expecting more articles for MVC from your end.
Reply | Email | Modify 
This is old technology by Ruben On October 7, 2008
This frameworks are build on java applications some years ago. An example is Apache Struts, that was built since 2000. Microsoft should watch java platform and copy their ideas before.
Reply | Email | Modify 
Re: This is old technology by Kalyan On October 7, 2008

Hi

i accept idea may be old but implementation in .NET is different. Here URL routing concept is introduced in MVC. Is this feature is defined in JAVA MVC.

Reply | Email | Modify 
Re: Re: This is old technology by Ruben On October 7, 2008

Hi,

One of the base concepts of apache Struts and other java MVC frameworks is url routing. Maybe the ASP.NET implementation was a good implementation, your article explain it very well, but I don't undestand why Microsoft build this framework now and not at the moment that it built ASP.NET Forms.

If you don't know Java platform learn it, you will find a lot of ideas that Microsoft is copying now and other advanced ideas.

Another very good example: Entity Framework vs EJB
Reply | Email | Modify 
question by Marc On October 23, 2008
Hi, I don't see this template from my vs 2008 pro. Does this project template only exists on VSTS versions or belongs to an extension? Thanks, Marc
Reply | Email | Modify 
Re: question by Kalyan On October 23, 2008

Hi

You need to install VS 2008 SP1 to get the template!

Kalyan

Reply | Email | Modify 
Re: Re: question by Marc On October 23, 2008
I will thanks
Reply | Email | Modify 
Re: Re: question by Kashif On November 27, 2010
Is it any other way to get MVC in VS 2008 , I have VS 2008 with SP2 but i didn;t find tht in it
Reply | Email | Modify 
good article kalyan by rammohan On November 18, 2008
please keep more articles on this topic, and give me ur mail id if i have any doubys i will contact u my mail id: ramu_mohan69@yahoo.co.in please send one test mail
Reply | Email | Modify 
nice article by gautam On December 9, 2009
very well written.
helpful for beginners.
I have two doubts.
1)can all traditional applications be developed using mvc asp.net technology.?
2) or should we select between 2 technologies before developing the applications?
Reply | Email | Modify 
convert asp website to MVC by meera On February 13, 2010
i have a website with BAL, BO , DAL , layers in addition to ASPX pages ....
How do i identify which layer can be incorporated into the folders Model, View and Contrioller  folders ??????????
Reply | Email | Modify 
Hi, by thant On January 26, 2011
I have one problem. When i run MVC Default Page, there is server error message appear. like this" Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.] System.Reflection.Assembly._GetType(String name, Boolean throwOnError, Boolean ignoreCase) +0 System.Reflection.Assembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) +42 System.Web.UI.Util.GetTypeFromAssemblies(ICollection assemblies, String typeName, Boolean ignoreCase) +145 System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError) +73 System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly) +111 System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData) +279 " How can i solve it?
Reply | Email | Modify 
Good one by Rajendra On October 11, 2011
good article. kalyan
Reply | Email | Modify 
ASP.NET 3.5 MVC Application by sumaira manzoor On November 16, 2011
hello sir; this is your good artical. do you have uml experties. becoz i need a help about uml diagrams regards sumaira manzoor
Reply | Email | Modify 
Discover the top 5 tips for understanding .NET Interop
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.