Web API Routing - multiple actions were found that match the request

前端 未结 1 1997
鱼传尺愫
鱼传尺愫 2021-01-02 11:53

I got this Route:

        routes.MapRoute(
            name: \"Default\",
            url: \"{controller}/{action}/{id}\",
            defaults: new { id = U         


        
相关标签:
1条回答
  • 2021-01-02 12:22

    I got this Route:

    What you have shown is a route for MVC controllers. I hope you realize that Web API controllers are an entirely different thing. They have their own routes defined in the ~/App_Start/WebApiConfig.cs.

    So make sure tat you have included the {action} token in your Web API route definition (which I repeat once again has nothing to do with your MVC route definitions):

    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{action}"
    );
    
    0 讨论(0)
提交回复
热议问题