How do I receive JSON data on my WebAPI backend in C#?
I have the following JSON sent from my JavaScript frontend.
{
    "User_Id": 1,
    "TotalPrice": 35,
    "DeliveryAddress": "At my house",
    "CartItems": [
        {
            "Id": 1009,
            "Name": "Superman juni 2014",
            "Quantity": 1,
            "Price": 35
        }
    ]
}
I have this classes:
public class PurchaseOrder
    {        
        public List<CartItem> CartItems { get; set; }
        public string DeliveryAddress { get; set; }
        public int TotalPrice { get; set; }
        public int User_Id { get; set; }
    }
public class CartItem
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Quantity { get; set; }
        public int Price { get; set; }
    }
And my WebAPI method:
[System.Web.Mvc.HttpPost]
        public bool AddOrder(PurchaseOrder order)
        {
            // Here I will do something
            return true;
        } 
I only get "null" as the result for my "PurchaseOrder order" object. Can the problem be that I´m using [System.Web.Mvc.HttpPost]? I have also tried [System.Web.Http.HttpPost], but get the same result. // Martin
application/jsonon the JavaScript request?orderwith your data and useJSON.stringifywhile posting.System.Web.Mvc.HttpPostit should come from theHttpnamespace I believe not theMvcone. Secondly this is something to do with your JavaScript.