Look at ASP.NET MVC 4 Project Structure
In this article, we will look into the Visual Studio project structure for MVC 4 application. We can install MVC 4 on top of VS 2010 SP1\2012 from here. After installing MVC 4 on VS 2010, create a new ASP.NET MVC 4 Web Application and name it as MVC4PrjStructure. It opens below window to select the type of project:
New templates in MVC 4 are
1) Mobile Application - It is used to create web application targeting mobile devices with Forms Authentication
2) Web API – It is used to develop HTTP services that targets broad range of clients like browsers, mobile devices, any applications that can understand HTTP protocol and it’s a platform for building RESTful applications.
Select Internet Application as Project type and click Ok. Open Solution Explorer and it is as shown below:
First noticeable change in project structure is in App_Start folder. Let’s look into it one by one:
1) AuthConfig.cs – This file contains code to register clients for external authentication providers like Facebook, Twitter etc. By default, this code is commented out, so none of the external providers are enabled.
2) BundleConfig.cs – This file contains code for configuring Bundling and minification features. Refer here for getting an idea on this feature.
3) FilterConfig.cs – This file contains code for registering filters. A filter is a method that contains logic need to be executed before or after an action method call.
4) RoutConfig.cs – This file contains code for registering the routes. A route defines mapping of incoming browser requests to particular MVC controller actions.
5) WebApiConfig.cs – This file contains code for configuring Web API like routes.
Prior to MVC 4, all the above settings can be defined in Global.asax file. For maintainability, It got split into different files.
In Filters folder, we can define filters for the application and separate folder for Images, which is not part of Content folder in this release.
Next major addition is packages.config. This file is managed by NuGet infrastructure for tracking\updating packages like jQuery, jQuery UI, EntityFramework, Modernizr etc and their version used in the application. It looks like as shown below:
For example, your application is using jQuery package 1.7 and you want to point it to 1.8. Prior to this release, we need to manually download the 1.8 version separately and include it in the project. In MVC 4, we can do it easily by just clicking on Manage NuGet Packages as shown below:
It will show up below window, where we can install\update the packages with its latest version:
The above project structure will also apply to Web API project. In Web API project, a controller is inherited from ApiController and won’t return a view in the action method as shown below:
This article covers changes included in MVC 4 project template. In coming articles, we will discuss more about MVC 4 features. I hope this article will be helpful for all.