0

from here i got a little touch about Setting an alternate controller folder location in ASP.NET MVC. here is the url Setting an alternate controller folder location in ASP.NET MVC

they guide us we can change the namespace and also specify the name space in routine code and these way we can solve it but this above link is not showing how to change or store controller related .cs files in other folder location.

suppose i want to store controller in folder called mycontroller in root then what i need to do. guide me please. thanks

UPDATE

You can do this using Routing, and keeping the controllers in separate namespaces. MapRoute lets you specify which namespace corresponds to a route.

Example

Given this controllers

namespace CustomControllerFactory.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
           return new ContentResult("Controllers");
        }
    }
}

namespace CustomControllerFactory.ServiceControllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
           return new ContentResult("ServiceControllers");
        }
    }
}

And the following routing

 routes.MapRoute(
           "Services",
           "Services/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            new string[] { "CustomControllerFactory.ServiceControllers" } // Namespace
        );


        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            new string[] { "CustomControllerFactory.Controllers"} // Namespace
        );

You should expect the following responses

/Services/Home

        ServiceController

/Home

        Controllers
Community
  • 1
  • 1
Thomas
  • 33,544
  • 126
  • 357
  • 626
  • Maybe MVC areas would be worth checking out. http://msdn.microsoft.com/en-us/library/ee671793%28v=vs.100%29.aspx – matk Nov 14 '13 at 08:14

2 Answers2

0

There is no need to do anything, storing controllers in Controllers is only convention, not a requirement. Basically you can store controllers in any folder.

Petr Abdulin
  • 33,883
  • 9
  • 62
  • 96
  • if i store productcontroller.cs file in product folder then how request can come to productcontroller. what extra i need to set in routine code as a result asp.net engine could understand where to look for productcontroller. please guide me. thanks – Thomas Nov 14 '13 at 08:52
0

Check your RouteConfig.cs and you will probably find that a namespace has been defined for each route. You controller classes can be placed anywhere in the project as long as they still match the namespace defined in your routes.

JDandChips
  • 9,780
  • 3
  • 30
  • 46