WebAPI No action was found on the controller

后端 未结 1 827
闹比i
闹比i 2021-02-01 12:36

I got an error - No action was found on the controller \'Action\' that matches the request.

The url is http://localhost:37331/api/action/FindByModule/1.

相关标签:
1条回答
  • 2021-02-01 13:06

    This is because there is a parameter name mismatch. From your route the value 1 is assigned to parameter named id and your action is looking for parameter named moduleId.

    First option is to change your route like this:

    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{action}/{moduleId}",
        defaults: new { moduleId = RouteParameter.Optional }
    );
    

    Second is to change your URL like this:

    http://localhost:37331/api/action/FindByModule?moduleId=1
    

    So the parameter name match.

    0 讨论(0)
提交回复
热议问题