I have a method in my Web API Controller:
[HttpPost]
public void Post([FromBody]Registration registration)
{
// omitted
}
I am able to invoke the method but the parameter is always null. Registration class is defined as:
public class Registration
{
public int Id { get; set; }
public IStudent Student { get; set; }
}
public interface IStudent
{
string FirstName { get; set; }
string LastName { get; set; }
}
public class Student : IStudent
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
It seems the Student property of Registration being an interface is what's causing this since when I try to replace it with a concrete type, it binds just fine.
How do I make this bind when using an interface? Also, on my original Web API, I am accepting a parameter of type Registration. Is it possible also to make this as an Interface (IRegistration) and still bind?