ASP.NET MVC Example - Part 1
I am starting an example on ASP.NET MVC; I am planning to have 3 parts of this example so that it will be easy for understanding.
Structure of the example:
Part – 1: Creating basic MVC project
Part – 2: Creating Business Logic layer
Part – 3: Interacting with Model
To create an ASP.NET MVC web application, go to New Project and select C# / VB.NET any of your language preference projects, when select Web projects you will see ASP.NET MVC Web Project template at right window select it, and change the project name to StudentMVCExample and Click Ok.
After click ok there will be a dialog box asking “do you want to create a testing project?” say no.
Once project is created you will see many files and some folder are added by default, I will be explaining those files bit later.
Let us understand how URL routing works in ASP.NET MVC web application, if you open global.asax file,
Normally in MVC application you will not request for an .aspx page but you will request for an Action, this action is identified by a Controller class and executes the action provides output in View; MVC application URL pattern will be http://www.YourWebSite.com/Controller/Action/Id
If you observe in above screen, controller is set to Home Action is set to Index and Id is set to empty string, this default routing set by Visual Studio for our convenience.
Let me explain what is Controller and View here.
Controller is a class which takes requests from the user, Controllers are invoked by MVC framework reading the URL, this controller class will have all the Actions listed in them, for example Index Action, each Action in the controller class will have View in the View Section as you can see the above screen shot.
Now just press F5 to run the application, as of now we have not done any thing in our project we will see a default home page
If you observe the URL of the page, http://localhost:34343/ we have not specified any controller or action so it took from default routing and executes Home Controllers Index Action displays Index View
Now click on About button the right side and observer the URL
You can see Home/About, this means it executed Home Controllers About Action and displayed the About View.
A View is place where you will display the content received from the Action method, normally view are content pages which are linked to a master page.
I hope this will give a high level over view of the basic ASP.NET MVC web application; I will be posting how to handle with Model (business logic layer) in MVC architecture in next part of this article.
Happy Coding
Cheers,
Satish.




