0

I have a controller defined in a library. I'd like this controller to be accessible via any of my 3 areas. At the moment, the controller (let's say "contact") is not being found when accessed via for example the "admin" area (i.e. url of /admin/contact). It does however work when accessed via "/contact".

Is there any route configuration required to Areas in order to allow the access of a common controller though these areas?

Thanks.

James
  • 273
  • 2
  • 12

1 Answers1

1

You could put this controller in a namespace:

namespace MvcApplication1.Controllers.MyAreas
{
    public class ContactsController : Controller
    {
        ...
    }
}

and then in your area registration specify this namespace:

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Admin_default",
        "Admin/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional },
        new[] { "SomeLibrary.Controllers.MyAreas" }
    );
}

Now when you navigate to /admin/contacts/index the Index action of the ContactsController will be executed.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Thanks. I've seen similar suggestions on other threads however this didn't work for me. You have however confirmed that it should indeed work.....so I'll keep trying and see if I can get it to register. – James Oct 15 '12 at 10:55