Monthly Archives: November 2010

MVC and IIS

The Deployment of MVC Application is much straight fwd.. as far as Virtual directory and Mapping of our Application is concern.

The only twist while deploying the MVC Application because we never have the Extension of Pages while serving to user . This is some what like this “Scheduling/Index/24” etc.

Follow the following steps :

  1. Open the Property window of Virtual Directory (in our case “mvc”).
  1. Click on the Configuration Button.
  2. Now we need to add one new Extension to run MVC Application on IIS.
  3. Now search for “aspnet_isapi.dll” (you can get it easily by selecting .aspx extension and click on “Edit” button)
  4. Now restart the IIS and its done…

In this way we can Deploy MVC Application.

Advertisements

Creating First MVC Application (VS2010)

Creating First MVC Application :

Now just let the Application Open into VS and Hit run. Here we can see the very clean URL in browser and application by default displaying the Home Page of Application.

Now we will Add a new Page in the Application. There is nothing much complicated in doing so. For that we will first add a “Controller” who is actually responsible for the navigating and displaying a particular “View”.

After adding this Scheduling Controller, we are going to add another “View” called Scheduling which will be controlled by Scheduling Controller we have just added in our Application. For that just open the Scheduling Controller and right click and click on “Add View”.

Now to run this Scheduling View and see output, we need to place an Action Method for this View in Scheduling Controller which will return this Scheduling View. Here we need to take care of one thing is that , the name of Action Result Method should be same as that of View we have Added . In our case it is “Scheduling” and “Index” so we have added the method with the name “Scheduling”.

If we have mentioned a different name in to the ActionResult then it will go and Search this View Name in to the Shared Folder and if it is not even there then an Error Page is displayed from Shared Folder.

This Clean and Clear URL all is given by the “Route” which is defined in Global.asax file. User can define his/her choice of URL Route and the page will get displayed accordingly as shown in below screen shot…

 

 

 

 

What is a Model View Controller (MVC) Framework?

MVC is a framework methodology that divides an application’s implementation into three component roles: models, views, and controllers.

  1. “Models” in a MVC based application are the components of the application that are responsible for maintaining state.  Often this state is persisted inside a database (for example: we might have a Product class that is used to represent order data from the Products table inside SQL).
  2. “Views” in a MVC based application are the components responsible for displaying the application’s user interface.  textboxes, dropdowns and checkboxes .
  3. “Controllers” in a MVC based application are the components responsible for handling end user interaction, manipulating the model, and ultimately choosing a view to render to display UI.  In a MVC application the view is only about displaying information – it is the controller that handles and responds to user input and interaction.

MVC Flow

One of the benefits of using a MVC methodology is that it helps enforce a clean separation of concerns between the models, views and controllers within an application.  Maintaining a clean separation of concerns makes the testing of applications much easier, since the contract between different application components are more clearly defined and articulated.

One of the most Important feature of MVC :

It includes a very powerful URL mapping component that enables you to build applications with clean URLs.  URLs do not need to have extensions within them, and are designed to easily support SEO and REST-friendly naming patterns.

Model View Controller

For example, I could easily map the /products/edit/4 URL to the “Edit” action of the ProductsController class.