c# - Multiple actions were found that match the request http post method -


I have a problem with the web API. I have written these 3 works in the Controller Web API of my contact groups.

// Post API / Contact Group [System. Web. Hppost] public ineinmable & lt; Contact group & gt; All () {return _biz.GetAllContactsGroup (); } // post api / contact group / 5 [system. Web. Hpp Post] Public Contact Group FindById (Int ID) {return _biz.GetContactGroup (ID); } // Post API / Contact Group Public HTTPRPS Create Pensions Communications Group (Contact Group Item) {item.UserId = HttpContext.Current.User.Identity.GetUserId (); Item.DateAdded = DateTime.Now; If (ModelState.IsValid) return request. CreteSpons (HTTP.tat.code not acceptable, items); If (_biz.CreateContactGroup (item)) return request. Create Response (HTTPTat Code.NotFound, Item); HttpResponseMessage Response = Request CreateResponse (HTTP.tat.Code, Ready, Item); reaction. Header. Location = new uri (request. Request + item id. Toastring ()); Return feedback; }

When I want to send a http post method "/ api / contactgroups", this error will appear:

  {"$ id": " 1 "," Message ":" An error occurred. "," Exception message ":" Several actions found that match the request: \ r \ nSystem selection.Generic.Inumerable` 1 [NikSms.Models.ContactsGroup ] Type all () NikSms.Web.Api.ContactGroupsController \ r \ nSystem.Net.Http.HttpResponseMessageContactGroup type NikSms.Web.Api.ContactGroupsController "," ExceptionType ":" System.InvalidOperationException " , "StackTrace": "System.Web.Http.Controllers.ApiControllerActionSelector.ActionConstrictorActionSelector.ActionSelecto Http.ApiController.ExecuteAsync (HttpControllerContext control) on System.Web at rCacheItem.SelectAction (HttpControllerContext ControllerContent) on \ r \ n System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction (HttpControllerContextControllerCusic) \ r \ nCancel, cancellation token cancellation token ) \ R \ nSystem on M.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore (HttpRequestMessage request, cancellation token cancellation token) \ r \ nSystem on. Web. Http.Dispatcher.HttpControllerDispatcher. & Lt; SendAsync & gt; This is the WebApiConfig.cs content:  
  config.MapHttpAttributeRoutes (); Config.routes.MapHttpRoute ("DefaultApiCtrl");   , "API / {administrator} / {action} / {id}", new {id = route Parmeter.Optional}); Config.routes.MapHttpRoute ("DefaultApi", "API / {controller} / {ID}", New {id = RouteParameter.Optional});  

Can anyone help me solve it?

I got a better solution here: We can use the prefix [root name (" someRouteName ")] Please see the link below That's the description in Mike Wisson

Hope it helps


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -