Basic of MVC In-Depth

Synopsis

  1. Introduction
  2. Definition
  3. Advantages
  4. Disadvantages
  5. Flow of MVC
  6. Routing
  7. Simple MVC Form

Introduction

MVC is a one of the famous design pattern for developing web applications, Websites and web pages. It is much easier to developer compare to traditional ASP.NET. MVC has lot of advantages. MVC is a latest trend in the word. This article explains about basic structure of MVC and how to handle the MVC applications.

Definition

Model View Controller (MVC) is a design pattern or methodology. It is used to effectively develop web applications. MVC is a not complex one we can learn easily.

Advantages

There are many advantages are available in MVC.

  • A separation of Concern is main advantages of MVC. I t means we can divide into three part of application like Model, View and Controller.
  • Handle the code easily because of separation of concern.
  • In the same time we can split many developers work at a time. It will not affect one developer work to another developer work.
  • It supports TTD (test-driven development). We can create an application with unit test. We can write won test case.
  • Latest version of MVC Support default responsive web site and mobile templates.
  • We can create own view engine. It is syntax is very easy compare to traditional view engine.

Disadvantages

  • Cannot see design page preview like .aspx page. Every time want to run then see the design.
  • Understanding flow of application is very hard one. It is little bit of complex to implement and not suitable for small level applications.
  • Its deployment is little bit hard one.

Basic Work Flow of MVC

MVC work flow is different compare with ASP.NET. First understand MVC work flow then need to know everyone. Below diagram explain work flow of MVC.


Routing

Routing is a finding available URL Request from which one user given URL. Routing is pattern matching system with the help of routing table. Routing table is containsall available routes basted on controller and action. If enter any one URL, routing engine compare given URL with route table. If given URL not available it shows error otherwise it renders corresponding page.

Route Table

Routing table is contains all possible way of URL based on controller and action methods. Whenever enter URL in browser Routing engine match with route table. In below screen shot shows how many action methods available in one controller.

In “Home” controller contains three action methods so three different ways of URL request possible. I have different controller and action possible way of URL request increase. All URL request are based on controllers and actions.

Possible way of URL Request below:

If give any other URL request it shows error like below screen shots.

Simple MVC Application

Below steps follow for open simple MVC default application. Learn many concepts from MVC default application. MVC 5 is available in Visual Studio 2013 and above.

  1. Open Microsoft Visual Studio then choose New Project then show the screen likes below.
  1. Click Web and select ASP.NET Web Application. Give specified name in Name Colum if you need choosewhich location your project wants to store then click Ok button.
  2. After click Ok then select a template need like Empty, Web Forms, MVC , Web API and Single Page Application.

  1. Select MVC it shows above image. If need unit testing for your application select Add unit tests check box.
  2. Directly host our application in cloud using Hosting in Cloud option marked in Red color. If want to host in cloud need to register and get cloud account.
  3. Finally click ok button then it is take few minutes to open application. After opening we can see what the necessary folders on right side are in coding page of MVC.
  1. App_Data, App_Start, Content, Fonts, Model, Script, Views and Web.Config are available in Solution Explore.
  2. In default application need not do any coding it has everything just run can see output like below.

Conclusion

MVC support responsive Website with the help of bootstrap. It is default available in MVC 4 above. This article helps to those who learn MVC newly as well as explained basic thing of MVC. Can learn advance concept of MVC in feature article.