我正在尝试将 json 绑定到我在 ASP .net MVC 4 中的模型。模型确实被创建但属性未填充。
我的JavaScript:
$.ajax({
type: 'POST',
url: "/Admin/" + method,
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(form.serializeArray()),
success: function (data) {
if (data.Success == true) {
}
}
});
我的课:
public class Taxes {
public int Id { get; set; }
public string Name { get; set; }
public decimal Rate { get; set; } }
我的方法:
[HttpPost]
public JsonResult AddTax(Taxes tax)
{
return Json(new { Success = true, tax.Id });
}
杰森:
[{"name":"Id","value":"1"},{"name":"Name","value":"fsdfs"},{"name":"Rate","value":"18"}]
结果是:
Id = 0
Name = Null
Rate = 0