Rithik Banerjee

Rithik Banerjee

  • 1.1k
  • 1k
  • 17.4k

Post Action method overload with same route name in API Controller

Jul 21 2020 5:21 AM
Is it possible to have two actions with same route name and same method but different parameter?
I want this:
  1. [HttpPost]    
  2. [Route("gstr4")]    
  3. public HttpResponseMessage SubmitGSTR4([FromBody] RequestPayloadWithoutSign requestPayload)    
  4. { }    
  5.     
  6. [HttpPost]    
  7. [Route("gstr4")]    
  8. public HttpResponseMessage FileGSTR4([FromBody] RequestPayloadWithSign requestPayload)    
  9. { }    
I got a HTTPStatusCode of 500 (InternalServerError) and here is the response payload:
  1. {"Message":"An error has occurred.","ExceptionMessage":"Multiple actions were found that match the request: \r\nFileGSTR4 on type APIPortal.Controllers.GSTR4Controller\r\nSubmitGSTR4 on type APIPortal.Controllers.GSTR4Controller","ExceptionType":"System.InvalidOperationException","StackTrace":"   at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\r\n   at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n   at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}  

Brought to you by:

Answers (2)