This is the first time i'm working with Web API. i'm trying to call a web api through a jquery ajax call. ajax call hits the web api action successfully but the string parameter "xx" is always null.
Ajax call
var x = "chamara";
$.ajax({
type: 'POST',
url: 'http://localhost:1557/api/values/mytest',
data: '{"xx":"' + x + '"}',
dataType: 'json',
});
Web Api action.
[AcceptVerbs("GET", "POST")]
public void mytest([FromBody]string xx)
{
string a = xx;
}
web api routes configuration.
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { action = "get", id = RouteParameter.Optional }
);