3

I have created a folder admin inside controller folder and wrote few controllers in it. I want to access all functions in that controllers in that folder by a url like abc.com/admin//.

I can get it working directly when its put directly in controller folder.

EDIT

WHAT HAVE YOU TRIED?

  • Just created a folder and wrote normal controllers in it. But I don't know how to route it.
Ajoe
  • 67
  • 8

2 Answers2

1

Add a route for the admin controllers in your route config if you want to support that path in the URL. Something like:

routes.MapRoute(
    name: "Admin",
    url: "admin/{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

But @DotNetDreamer is right that Areas are a better solution for the admin functionality of your site.

JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
1

Well, i would suggest, rather than just creating a folder and create controllers inside of it. You should create an Area
When you create an Area in asp.net mvc, it will automatically create folders(controller, model etc) for you. And the routing setup as well.
For more info, please visit http://www.codeguru.com/csharp/.net/net_asp/mvc/article.php/c20227/Using-Areas-in-ASPNET-MVC-Application.htm

Idrees Khan
  • 7,702
  • 18
  • 63
  • 111