I have a web application, built with MVC, Web API 2. Server side - C#, client - JS.
I have a problem with receiving class objects in my controller. Suppose, there is an hierarchy of classes:
class Person
{
public string Name { get; set; }
}
class Student : Person
{
public double Grade { get; set; }
}
class Professor : Person
{
public string University { get; set; }
}
In my controller, I have a method, which receives an object of the Person type:
[HttpPost]
public HttpResponseMessage AddPerson(Person person)
{
...
}
The Client is sending the correct object (either Student or Professor), but the controller does not know how to deserialize it from Json and always gets null.
Any ideas of how can I cause the server to deserialize the parameters correctly?