user1318054
user1318054

Reputation:

Controllers within controllers?

I'm somewhat new to MVC3, so I have a few questions...

I am creating a blog type website that I plan to expand to include many other things. Currently I have an AdminController in my project that has ViewResult's for the various things I want to take control of.. so for example:

public ViewResult Blog()
{
    var model = db.Posts.ToList();

    return View(model);
}

and another for pages, navigation, user management etc.

My question is... I want to have an additional controller for each section... so BlogController, NavigationController, etc. These should add to the URL as follows...

/Admin/Blog/Create
/Admin/Blog/Edit
/Admin/Navigation/Create

... and so on

I am guessing that I have to inherit from the AdminController something like:

public class BlogController : AdminController

and also create a custom route map?

Any advice or direction would be very helpful.

Thanks!

Upvotes: 3

Views: 99

Answers (1)

Ethan Brown
Ethan Brown

Reputation: 27282

You may want to look into areas; basically this allows you to have another level of depth for your controllers. In other words, you would add an "Admin" area, and then within that area, you'd have "Blog" and "Navigation" controllers. Here's a tutorial on how to set up areas:

http://www.c-sharpcorner.com/UploadFile/b19d5a/areas-in-Asp-Net-mvc3/

Upvotes: 3

Related Questions