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

break point hit


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -