2

I want to create a subfolder for my controllers.

This is my folder structure:

This is my folder structure.

What is the best way to get the below result?

localhost/home

Controller: Common/Home
View: Common/Home


localhost/product

Controller: Catalog/Product
View: Catalog/Product

1
  • Have a look at MvcCodeRouting - an open source project that enables MVC to use hierarchial folder structures. Commented Dec 30, 2017 at 11:04

2 Answers 2

4

In asp.net MVC Controllers, folders are ignored, as long as the cs files are set to compile they will be compiled into the DLL file and referenced by taking the class name (i.e ProductController) and dropping the word Controller from the end.

So the folder structure is largely up to yourself for whatever makes sense for your own project management.

If you are trying to get certain URLs to direct to certain controllers have a look at Routing instead.

Sign up to request clarification or add additional context in comments.

Comments

1

Use routes.MapRoute for routing see below example:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
        "Blog",                                           // Route name
        "Archive/{entryDate}",                            // URL with parameters
        new { controller = "Archive", action = "Entry" }  // Parameter defaults
    );
    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.