c# - How to POST via $.ajax() to ASP.NET WEB API? -
i keep getting null parameter once web api method hit. doing wrong?
var product = { name: "producta", id: 22 }; $.ajax({ url: 'http://localhost:50175/api/values/', type: 'post', data: product }) .success(function(data) { alert('success'); })
web api
// post api/values [httppost] public void post([frombody]product value) { setresponse(); }
product class
public class product { public string name { get; set; } public int id { get; set; } }
you need append post
url:
var product = { name: "producta", id: 22 }; $.ajax({ url: 'http://localhost:50175/api/values/post', type: 'post', data: product }) .success(function (data) { alert('success'); })
screen shot
Comments
Post a Comment