Changing the ASP.Net MVC Directory Structure

I have been working with ASP.Net MVC (3) for some time, and I really like it. But one thing that I find a little annoying is to constantly look at the controllers / views / models / script directory. So I am wondering if there is a way to tell MVC to look for files elsewhere?

Maybe someone can tell me how easy it is to group files together with a controller, for example:

Directory: / Membership

  • MembershipController
  • Logonview
  • Logonmodel
  • Registerview
  • RegisterModel

Regards Olav

+3
source share
5 answers

I know exactly what you're talking about. Here are the conditions under which I think that the default MVC folder structure is cumbersome:

  • I use the model per view approach
  • javascript,

?

"", ~/Views/MyEntityList ( MVC), , :

  ~/Views/MyEntityList/
       MyEntityListController.cs
       MyEntityListModel.cs
       MyEntityList.js
       MyEntityList.aspx

, , . MVC , , .js.

, . (. Los Techies ) .

+2

, Solution Navigator Power Tools VS 2010.

, , , , . .

, , :

MyApp.Domain

, , .

, Areas .

+1

" " , - , , , :

:/

  • MembershipController
  • LogOnView
  • LogOnModel
  • RegisterView
  • RegisterModel

... ~/Views/Membership

+1

, - . , .

0

, , - . Controllers/Membership

  • MembershipController
  • LogOnView
  • LogOnModel
  • RegisterView
  • RegisterModel

, , . , mvc .

 public class CustomViewEngine : RazorViewEngine
 {
    public CustomViewEngine()
    {
        ViewLocationFormats = new[]
         {
            "~/Controllers/{1}/{0}.cshtml",

        };
    }
 }

global.asax.cs ViewEngine Application_Start(),

 ViewEngines.Engines.Clear();
 ViewEngines.Engines.Add(new CustomViewEngine());

, , Layout, _Layout.cshtml.

, AreaViewLocationFormats.

, , FileExists, CreateView, CreatePartialView.

. web.config views Membership. mvc , viewbag, model ..

0

Source: https://habr.com/ru/post/1790191/


All Articles