dtsg
dtsg

Reputation: 4459

MVC Controller within another controller?

I'm wondering whether it's possible to have several nested controllers within one main one in MVC 3? For example:

public class AdminController : Controller
{
    public class PagesController : Controller
    {
    }
    //More controllers
}

I've tried this but couldn't get it to work, have modified my routes in global.asx but still nothing. How can I call the correct controller from AdminController when the url is for example:

/Admin/Pages/Index

Upvotes: 0

Views: 659

Answers (2)

Daniel A. White
Daniel A. White

Reputation: 191058

No this is not allowed. The controller factory won't be able to resolve it.

Upvotes: 0

mgnoonan
mgnoonan

Reputation: 7200

It sounds like what you are after is Areas. That will give you the URL routing structure you are seeking, but it does not use "controllers within controllers" to accomplish this.

Instead you will have an Admin area with a Pages controller in that area.

Upvotes: 7

Related Questions