I am trying to POST
Json
data to API
and read the value from the key using the HttpContext.Current.Request
object.
Client Side:
var data = { Name: "Tom" };
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json",
success: function (response) {
}
});
In API:
[HttpPost]
[Route("UploadProduct")]
public HttpResponseMessage Upload()
{
if (string.IsNullOrEmpty(HttpContext.Current.Request["Name"]))
return "Name is missing";
//... removed for brevity
}
Why key Name is always empty ?
I know Json
data will bind to model object only. But like to know if it's possible to get data from HttpContext.Current.Request
object by making some changes in client side ?