I am using Asp.Net web forms with WebAPI 2. I have a method which works with GET but when I use POST then it doesn't work. If you see below there is a break point inside that method and it doesn't even reach there when calling POST. Strangely when I use Postman to test the method then it works with POST. What am I doing wrong?
My jquery code
$.ajax({
url: 'MyController/GetUserDetail',
type: 'POST',
async: true,
dataType: 'json',
data:
{
"search": myvariable
},
success: function (response) {
}
});
My Web API method. When using [HttpGet] and also changing jquery from POST to GET, then it works. But for POST this method is never called as breakpoint never hits and I don't receive any error either.
[HttpPost]
public User GetUserDetail(string search)
{ //breakpoint here
}
My route config
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}