I have the following .Net class:
public class Product { public int ID {get;set;} public String Name {get;set;} public Decimal Price {get;set;} }
And the action in my controller:
[HttpPost] public ActionResult AddProduct(Product product) {
The JSON string sent in the AddProduct request looks like this (captured via Fiddler2):
POST http://localhost:59656/Cart/AddProduct HTTP/1.1 Host: localhost:59656 Origin: http://localhost:59656 X-Requested-With: XMLHttpRequest User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko Chrome/17.0.963.79 Safari/535.11 Content-Type: application/json; charset=UTF-8 Accept: text/html, */*; q=0.01 {"Product":{"ID":1232, "Name":"Blu-Ray","Price":210}}
Why is product.Price zero, while other properties (ID and Name) are properly moistened?
Diego source share