Web API: Same Method with different HTTP Verbs

后端 未结 4 635
鱼传尺愫
鱼传尺愫 2021-01-06 12:48

In a WEB API controller, can we have the same method name with different HTTP Verbs?

  [HttpGet]
        public string Test()
        {
            return \"         


        
4条回答
  •  广开言路
    2021-01-06 13:42

    Comment out the following code:

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

    And write the following code:

    config.Routes.MapHttpRoute("DefaultApiWithAction", "api/{controller}/{action}");
    

提交回复
热议问题