2

I'm building a web application using ASP.NET MVC and i have a question about the files organization.

So, i want to create the following structure:

App_Something
Controllers
Views
Models
Areas // I think area is for logic separation.
    Private
        Controllers
            Registers
                ProfileController.cs
                UserController.cs
            OtherFolder
                ChildFolder
                    OtherController.cs
        Views
            Registers
                Profile
                    Index.cshtml
                    Create.cshtml
                    Edit.cshtml
                    Delete.cshtml
                User
                    Index.cshtml
                    Create.cshtml
                    Edit.cshtml
                    Delete.cshtml
             OtherFolder
                ChildFolder
                    Other
                        Index.cshtml
                        Create.cshtml
                        Edit.cshtml
                        Delete.cshtml
        Models

So, i want separate my project files into different folders, but when i do this the viewEngine don't find my views.

First of all... I can separate my project like above? Its, ok?!

for now, this is my code:
Add a route for the controllers actions of Registers folder

    public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute
        (
            "Private_Registers",
            "Private/Registers/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );

        context.MapRoute
        (
            "Private_default",
            "Private/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

But, when i run this... The ViewEngine can't find the views into the folder.

I need create a custom viewEngine file with the views locations?

leojnxs
  • 127
  • 1
  • 7

1 Answers1

0

You can do that, but you'll have to render with

Html.Partial or Html.RenderPartial the views path - current location .

Basic structure is

  • Areas
    • Admin
      • Controllers
        • UsersController
      • Views
        • Users
          • Index.cshtml

For difference between Html.Partial and Html.RenderPartial look here

Community
  • 1
  • 1
Razvan Dumitru
  • 11,815
  • 5
  • 34
  • 54
  • Its not my case... I just want know how to separate my project using folders, i needc create a custom viewEngine file to change views location??? – leojnxs Nov 19 '13 at 14:14
  • I don't really know how to do that. You can have double views, 1 view in correct location for rendering the view in your custom folder for every view , but this is bad. – Razvan Dumitru Nov 20 '13 at 13:14
  • My friends told me that tis is non practicable. Its over organization, ty by the way. – leojnxs Nov 21 '13 at 09:33