0

I am using MVC 4, I created an admin folder and my controller actions are referencing the views in the admin folder like:

   /controllers/admin/UserController.cs

My views are here:

/views/admin/users/index.cshtml

My controller action looks like:

 public ActionResult Index()
 {
    return View("~/Views/Admin/Users/Index.cshtml");
 }

How can I now setup the routes for all my admin controllers so that the URL has the 'Admin' folder in the URL:

http://localhost/admin/user/index

Note: MVC 4 does not have "areas".

cool breeze
  • 4,461
  • 5
  • 38
  • 67

1 Answers1

3

What you are looking for is Areas.

Areas allows you to logically group related code. you can think of it as a sub mvc app with controllers & views inside your mvc app.

You may simply create an area called "Admin". You will be able to create controllers & views inside that. When you create the area, Visual studio will automatically add the route definition for this area which will include the area name (Admin) in the route. Inside the area (~/Areas/Admin) you will be able to see a class called "AdminAreaRegistration.cs" where the route definition for this area is defined.

Shyju
  • 214,206
  • 104
  • 411
  • 497