a small testing code.
//web api 2 controller
[HttpPost]
[Route("api/test")]
public IHttpActionResult Test(Person request)
{
var name = request.name;
var age = request.age;
return Json("ok");
}
}
//model
[Serializable]
public class Person
{
public string name { get; set; }
public int age { get; set; }
}
and I just send json model in POST request
{
"name": "mike",
"age": 12
}
Why that code doesn't work (model came empty) if model Person has [Serializable] attribute? If I remove it starts working. The problem is I have to use those existing models and I don't understand why asp.net stop mapping them? Is JSON model which I send with POST request must be formated in another way?