Multiple actions were found that match the request http post method

Hamid

I have a problem with Web Api 2. I have wrote these 3 actions in my ContactGroupsController web api.

// POST api/contactgroups
[System.Web.Http.HttpPost]
public IEnumerable<ContactsGroup> All()
{
    return _biz.GetAllContactsGroup();
}




// POST api/contactgroups/5
[System.Web.Http.HttpPost]
public ContactsGroup FindById(int id)
{
    return _biz.GetContactGroup(id);
}




// POST api/contactgroups
public HttpResponseMessage CreateContactGroup(ContactsGroup item)
{
    item.UserId = HttpContext.Current.User.Identity.GetUserId();
    item.DateAdded = DateTime.Now;

    if (!ModelState.IsValid)
        return Request.CreateResponse(HttpStatusCode.NotAcceptable, item);

    if (!_biz.CreateContactGroup(item)) return Request.CreateResponse(HttpStatusCode.NotFound, item);

    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, item);
    response.Headers.Location = new Uri(Request.RequestUri + item.Id.ToString());
    return response;
}

when i want to send an http post method to "/api/contactgroups" this error appears:

  {
    "$id": "1",
    "Message": "An error has occurred.",
    "ExceptionMessage": "Multiple actions were found that match the request: \r\nSystem.Collections.Generic.IEnumerable`1[NikSms.Models.ContactsGroup] All() on type NikSms.Web.Api.ContactGroupsController\r\nSystem.Net.Http.HttpResponseMessage CreateContactGroup(NikSms.Models.ContactsGroup) on type NikSms.Web.Api.ContactGroupsController",
    "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.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()"
}

this is WebApiConfig.cs contents:

config.MapHttpAttributeRoutes();
        config.Routes.MapHttpRoute(
                                     "DefaultApiCtrl",
                                     "api/{controller}/{action}/{id}",
                                     new { id = RouteParameter.Optional});

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

can anyone help me to solve it?

Hamid

I found a better solution here: we can use prefix [RouteName("someRouteName")] please see link below that Mike wasson describes it in Route Prefixes

hope it helps

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple actions were found that match the request http post method

From Dev

webapi: Multiple actions were found that match the request

From Dev

Multiple actions were found that match the request - WebApi

From Dev

Multiple actions were found that match the request: System.Net.Http.HttpResponseMessage

From Dev

Multiple actions were found that match the request: System.Net.Http.HttpResponseMessage

From Dev

Multiple actions were found that match the request when I add another method to controller (RPC)

From Dev

Multiple actions were found that match the request when I add another method to controller (RPC)

From Dev

Multiple actions were found that match the request error when adding a second GET action method to web api controller

From Java

Multiple actions were found that match the request in Web Api

From Dev

Manually creating route alias with custom DirectRouteProvider causes "Multiple actions were found that match the request" error

From Dev

WebApi 'Multiple actions were found that match the request' error after making call in angular

From Dev

c# OWIN Web API - Multiple actions were found that match the request:GET

From Dev

BaseController input param Object results in Multiple actions were found that match the request

From Dev

Web Api Multiple actions were found

From Dev

Why am I getting "Multiple actions were found ..." when I have exactly one Post action?

From Dev

Multiple types were found that match the controller named 'Home'. (weird error)

From Java

HTTP Request in Swift with POST method

From Dev

Post int as part of method but get No HTTP resource was found that matches the request URI error

From Dev

Zend Framework forward request with post http method

From Dev

400 Bad Request for $http post method

From Dev

Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL

From Dev

Multiple types were found that match the controller named 'Account'. MVC 4 & using RouteConfig.CS

From Dev

MVC Routing with Matching Controllers in Areas: Multiple types were found that match the controller

From Dev

Multiple types were found that match the controller named 'Home' After creating MVC Forum

From Dev

Getting "multiple types were found that match the controller" error when submitting a form

From Dev

Laravel 4 Undefined Method Illuminate Http Request Request::post()

From Dev

Error : No exports were found that match the constraint:

From Dev

no exports were found that match the constraint:ContractName

From Dev

HTTP/1.1 404 Not Found - jQuery POST request to Rails route

Related Related

  1. 1

    Multiple actions were found that match the request http post method

  2. 2

    webapi: Multiple actions were found that match the request

  3. 3

    Multiple actions were found that match the request - WebApi

  4. 4

    Multiple actions were found that match the request: System.Net.Http.HttpResponseMessage

  5. 5

    Multiple actions were found that match the request: System.Net.Http.HttpResponseMessage

  6. 6

    Multiple actions were found that match the request when I add another method to controller (RPC)

  7. 7

    Multiple actions were found that match the request when I add another method to controller (RPC)

  8. 8

    Multiple actions were found that match the request error when adding a second GET action method to web api controller

  9. 9

    Multiple actions were found that match the request in Web Api

  10. 10

    Manually creating route alias with custom DirectRouteProvider causes "Multiple actions were found that match the request" error

  11. 11

    WebApi 'Multiple actions were found that match the request' error after making call in angular

  12. 12

    c# OWIN Web API - Multiple actions were found that match the request:GET

  13. 13

    BaseController input param Object results in Multiple actions were found that match the request

  14. 14

    Web Api Multiple actions were found

  15. 15

    Why am I getting "Multiple actions were found ..." when I have exactly one Post action?

  16. 16

    Multiple types were found that match the controller named 'Home'. (weird error)

  17. 17

    HTTP Request in Swift with POST method

  18. 18

    Post int as part of method but get No HTTP resource was found that matches the request URI error

  19. 19

    Zend Framework forward request with post http method

  20. 20

    400 Bad Request for $http post method

  21. 21

    Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL

  22. 22

    Multiple types were found that match the controller named 'Account'. MVC 4 & using RouteConfig.CS

  23. 23

    MVC Routing with Matching Controllers in Areas: Multiple types were found that match the controller

  24. 24

    Multiple types were found that match the controller named 'Home' After creating MVC Forum

  25. 25

    Getting "multiple types were found that match the controller" error when submitting a form

  26. 26

    Laravel 4 Undefined Method Illuminate Http Request Request::post()

  27. 27

    Error : No exports were found that match the constraint:

  28. 28

    no exports were found that match the constraint:ContractName

  29. 29

    HTTP/1.1 404 Not Found - jQuery POST request to Rails route

HotTag

Archive