despite I dug into stackoverflow and a lot of documentation, I am stuck on that: I am not able to send an object via jquery ajax to a c# mvc application. Always the values of attributes of the order I return in the controller seems empty.
Thanks for any help!
JAVASCRIPT
function Order()
{
this.Partner;
this.OrderID;
this.TypeOfOrder;
this.SubmittedBy;
this.CompanyID;
this.CompanyName;
}
jQuery('button[type="submit"]').click(function (event) {
event.preventDefault();
var order = new Order();
order.Partner = "ABC",
order.OrderID = "123";
order.TypeOfOrder = "Website";
console.log(order);
jQuery.ajax({
url: "/my-route",
type: "POST",
dataType: 'json',
contentType: "application/json",
data: order,
success: function (data) {
console.log(data);
},
failure: function (response) {
console.log("ERROR!");
}
});
})
C# Model
public class Order
{
public string Partner { get; set; }
public string OrderID { get; set; }
public string TypeOfOrder { get; set; }
public string SubmittedBy { get; set; }
public string CompanyID { get; set; }
public string CompanyName { get; set; }
}
C# Controller
// POST my-route
[HttpPost]
public Order Post(Order order)
{
return order;
}
CONSOLE

contentType: "application/json",(either that or you need to usedata: JSON.stringify(order),)