0

I have my file structure setup as:

Controllers/Requestor/RequestorHomeController (Namespace: Proj.Presentation.Controllers.Requestor)
Controllers/Approver/ApproverHomeController (Namespace: Proj.Presentation.Controllers.Approver)

My routes look like:

routes.MapRoute(
            name: "PrependRequestor",
            url: "requestor/{controller}/{action}/{id}",
            defaults: new { controller = "RequestorHome", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "Proj.Presentation.Controllers.Requestor" }
        );

and

routes.MapRoute(
            name: "PrependApprover",
            url: "approver/{controller}/{action}/{id}",
            defaults: new { controller = "ApproverHome", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "Proj.Presentation.Controllers.Approver" }
        );

I am not receiving any errors, but when I go to Approver/ApproverHomeController/Index the first route is being hit because the url is requestor/approverhome. If it is in a different namespace, shouldn't that first controller be ignored? Any suggestions on what I can do to hit the second route?

Andrew
  • 2,013
  • 1
  • 23
  • 38

1 Answers1

1

The route

Approver/ApproverHomeController/Index

does not work because you must omit the "Controller" in the url.

It will work as

Approver/ApproverHome/Index

You also must get to the second route with

approver

because you have default values for the controller and action parts.

Update:

If you want to make a redirect from a controller in a different namespace you should use

return RedirectToAction("index", "approverhome", new { area = "approver" } );
DaniCE
  • 2,412
  • 1
  • 19
  • 27
  • So the URL should look like `requestor/{action}/{id}` and `approver/{action}/{id}`? – Andrew Dec 18 '14 at 17:28
  • no, requestor/{controller name without the "controller" part}/{action}/{id} edited the answer to clarify... – DaniCE Dec 18 '14 at 17:34
  • I'm sorry, either I'm not understanding you correctly or that isn't working. Could you type the full `routes.MapRoute` in your answer to make sure it's what I have now. – Andrew Dec 18 '14 at 17:43
  • I'm not actually typing in "Approver/ApproverHomeController/Index". I have a `RedirectToAction("index", "approverhome")` and that is making the url look like `requestor/approverhome`. – Andrew Dec 18 '14 at 17:45
  • In that case i think your problem is that you must specify the area in your RedirectToAction. See [this](http://stackoverflow.com/questions/1391887/redirecttoaction-between-areas) – DaniCE Dec 19 '14 at 08:18