I have a situation where I have several controllers in an administration "Area" in an ASP.NET MVC 5 application.
One of the controllers is working fine, the second controller is routing to the default route at the root of the site.
My default route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Reports", action = "Index", id = UrlParameter.Optional }
);
My area route:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Administration_default",
"Administration/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
My working area controller:
public class ResourcesController : Controller
{
// GET: Administration/Resources
public ActionResult Index()
{
using (var db = new SDRContext())
{
var resource = db.Resources.ToList();
return View(resource);
}
}
}
My non-working area controller:
public class DisplayFieldsController : Controller
{
private SDRContext db = new SDRContext();
// GET: Administration/DisplayFields
public ActionResult Index()
{
var results = db.DisplayFields.ToList();
return View(results);
}
}
Why when I call the second controller does it default to the root route instead of the administration route I have setup?