Controllers in controllers?
I'm a bit 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. I currently have an AdminController in my project that has a ViewResult for various things that I want to take control of .. so for example:
public ViewResult Blog()
{
var model = db.Posts.ToList();
return View(model);
}
and the other is for pages, navigation, user management, etc.
My question ... I want to have an additional controller for each section ... so BlogController, NavigationController, etc. They should add url like this ...
/Admin/Blog/Create
/Admin/Blog/Edit
/Admin/Navigation/Create
... etc.
I am assuming that I need to inherit from AdminController something like:
public class BlogController : AdminController
and also create your own route map?
Any advice or guidance would be very helpful.
Thank!
You may want to take a look at the areas; it basically allows you to have another layer of depth for your controllers. In other words, you would add an Admin area, and then in that area you would have the Blog and Navigation controllers. Here's a tutorial on setting up scopes:
http://www.c-sharpcorner.com/UploadFile/b19d5a/areas-in-Asp-Net-mvc3/
source to share