Anup Shah on WPF and Silverlight (Programming Garden)

IT 's For You!!!

Tuesday, October 23, 2012

MVC Basics

The ASP.NET MVC Framework is a web application framework that implements the model-view-controller pattern. Based on ASP.NET, it allows software developers to build a Web application as a composition of three roles:

ModelView and Controller

model represents the state of a particular aspect of the application. Frequently, a model maps to a database table with the entries in the table representing the state of the application.

controllerhandles interactions and updates the model to reflect a change in state of the application, and then passes information to the view.

view accepts necessary information from the controller and renders a user interface to display that


View - just the UI (HTML), there's no much logic there only logic for taking data from the Model. View just take a Model and render it's content on the page. There's no code behind, no .aspx.vb or .aspx.cs

Model - contains all data that view needs to display

Controller - is the boss, the controller handling HTTP requests for web page and it's role is to create a model (read data from DB, bussiness logic etc) and selects proper view for render. Controller never interacts with the user interface, it's job of the View. And never holds any data or statements, it's job of the Model.

Folder structure of app:
image_thumb1

  • "Controllers" folder is the place where the controllers are placed. The name convention is the controller name must end with "Controller" word, for eg.: HomeController -> Home is the name of the controller. And "Controller" is required postfix. In the code you using just a name (for eg. Home) but controller classes needs the have there the Controller postfix to be properly handled by MVC engine.
  • "Views" is the place for views.
    When the view represents action result (for eg. aspx page) then view name needs to match with action names used for.
    When view is usercontrol you can name it whatever you what.Under Views folder you will have list of folders with controller names and the one called Shared. The folders with the controller names are there just because the view is somehow associated with the controller. Another words when the controller return views that's the place where the MVC is looking for particular view that needs to be renders. The "Shared" folder is the place for user controls, master pages etc. The "Shared" folder contains views used by multiple controllers.
  • "Models" - place for object definitions that will be populated with the Controller and used by View for rendering.





No comments:

Post a Comment