Changing default directory structure in asp.net mvc - asp.net-mvc

I am working on asp.net mvc project which is quite large in size. I am new to the MVC stuff.
As Asp.Net MVC have default folder structure Controller, Views or Model so can we change this structure. what if instead of Controller i have different folder? Is it possible?

Although it is possible to change the LocationFormats of a view engine, this isn't recommended as it messes with the standard MVC conventions.
Instead, you should consider using Areas for each of your major 'modules' of functionality.
Your folder structure will then be similar to:
/(MVC Root)
/Areas
/Sales
/Controllers
/Views
/Financials
/Controllers
/Views
etc.

Related

Areas vs Folders in MVC

I am not to relate to Areas in MVC, why cannot we have simple folders to indicate modules, is the web.config which needs to be there, the below is the reason why i am asking this
Views -unfortunately for views it’s not possible. All the views must be placed inside “~/Views/ControllerName” or “~/Views/Shared” folder.
The following article describes in detail the reasons for Areas and the difference between Areas and folder-based conventions in ASP.NET MVC.
http://www.codeguru.com/csharp/.net/net_asp/mvc/article.php/c20227/Using-Areas-in-ASPNET-MVC-Application.htm
The essential idea is contained in the Introduction of the article:
ASP.NET MVC relies on certain folder and class naming conventions to
organize models, views and controllers. A large application often
consists of functionally independent modules with the result that the
main application is essentially a bundle of these sub-applications. In
such cases, organizing various models, views and controllers can be
tedious. Luckily, ASP.NET MVC allows you to split your application
into what is known as Areas. Each area mimics the folder structure and
conventions as required by ASP.NET MVC. This article shows you how
Areas are used in an ASP.NET MVC application.
When someone is trying to develop a sub-module suitable for inclusion in any ASP.NET MVC application (as an example, think deployment/inclusion of 3rd party code via a NUGET package) then the Areas construct is very helpful, and arguably a necessity.
Areas are folder structure which contains its independent set of Controller,
View, Model. Consider we are creating an area called Admin then the folder structure for the Admin area will be,
The same setup can be created by adding folders, Subfolder, and Required files.

javascriptmvc folder structure with asp.net mvc

It seems to me the first biggest hurdle of fitting javascriptmvc into asp.net mvc, is the folder structure. Has anyone adapted the asp.net mvc folder structure to serve up content files from the folder structure javascriptmvc expects?
using routes.IgnoreRoute("javascriptmvc-3.0.5/{*pathInfo}"); in your route definitions things should work as expected.

Two web.configs?

ASP.Net MVC applications has two web.configs. One in the root folder and one in the Views folder. Why?
From Pro ASP.NET MVC 2 book:
/Views/Web.config:
This is not your application’s main
Web.config file. It just contains a
directive instructing the web server
not to serve any *.aspx files under
/Views (because they should be
rendered by a controller, not invoked
directly like classic Web Forms *.aspx
files). This file also contains
configuration needed to make the
standard ASP.NET ASPX page compiler
work properly with ASP.NET MVC view
syntax.
One reason is to simplify your views and your pages. You can put the compilation or even the masterPageFile declaration from your views in this web.config, for example.
Phil Haack did a great post on this -> http://haacked.com/archive/2009/08/04/views-on-a-diet.aspx

Routing issue when using ASP MVC 2 areas

I am using asp mvc 2 areas. I am trying to set up the project such that when the web site is launced it calls one of the controllers in my areas instead of the default home page.
When I update the routes in the Global.asax file, it doesn't seem to work.
It is giving me an error since it is looking only in the views directory and not in the Areas folder. How can i force it to look into the Areas folder too?
Have you created a custom ViewLocator as described here: http://blog.codeville.net/2008/07/30/partitioning-an-aspnet-mvc-application-into-separate-areas/

How to customize directory structure in ASP.NET MVC?

The project I'm starting to work at will have several dozens of controllers, so it would be nice to structure them into logical directories and respective namespaces, like "Controllers/Admin/", "Controllers/Warehouse/Supplies/", etc.
Does ASP.NET MVC support nested controller directories and namespacing?
How do I manage routes to those controllers?
You can put the controllers anywhere; routes do not depend on where a controller is stored. It will be able to find any class that implements IController within your application.
I usually keep my controllers in a separate project, f.ex a MyProject.Frontend project, alongisde a MyProject.Frontend.Application project which is the actual entrypoint web project with the views etc.

Resources