asp.net web api - AJAX call can't find my WebAPI Controller -


i have following ajax call:

var params = {     provider: "facebook" };  $.ajax({     url: "http://localhost/taskpro/api/account/externallogin",     data: json.stringify(params),     type: "post",     contenttype: 'application/json; charset=utf-8' }) .done(function (response) {     alert("success"); }); 

calling following webapi controller:

public class accountcontroller : apicontroller {     [httppost]     [allowanonymous]     public bool externallogin(string provider)     {         return true;     } } 

with following routemap:

config.routes.maphttproute(     name: "defaultapi",     routetemplate: "api/{controller}/{action}/{id}",     defaults: new { id = routeparameter.optional } ); 

when execute this, fiddler returning:

{"message":"no http resource found matches request uri  'http://localhost/taskpro/api/account/externallogin'.","messagedetail": "no action found on controller 'account' matches request."} 

i have several other calls being made controller working fine. it's call giving me troubles.

also, if remove parameter in controller it's

public bool externallogin() 

and comment out data line in ajax, works fine.

any ideas why routing not working call?

i ran across article:

http://encosia.com/using-jquery-to-post-frombody-parameters-to-web-api/

basically, webapi can't bind primitive data types string. have either create model bind to, or use [frombody] attribute. modified method this:

public bool externallogin([frombody]string provider) 

and it's working fine now.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -