Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't this MVC Route Work?

I have the following routes defined in my RouteConfig class:

       routes.MapRoute(
             name: "DefaultMessage",
             url: "API/{action}",
             defaults: new { action = "MessageGateway" }
         ); 
        routes.MapRoute(
              name: "DefaultNoParms",
              url: "{controller}/{action}",
              defaults: new { controller = "API", action = "Login" }
         );

When I test this on my localhost with just localhost:65133/ as the address I am routed to the Login ActionResult on the APIController, but when I try localhost:65133/API I get the following error:

The matched route does not include a 'controller' route value, which is required

Can anyone tell me what is wrong? The ActionResult MessageGateway does exist...

like image 654
Bob Bartel Avatar asked Aug 01 '13 21:08

Bob Bartel


Video Answer


1 Answers

Seems like the error is self-explanatory - you need to tell it what controller to go to.

routes.MapRoute(
    name: "DefaultMessage",
    url: "API/{action}",
    defaults: new { controller = "API", action = "MessageGateway" }
); 
like image 161
Joe Enos Avatar answered Oct 01 '22 05:10

Joe Enos