I am writing a web-api in asp.net. I have following problems: I have an interface and a class implementing that interface
public interface Item
{
string Name { get; set; }
string Description { get; set; }
}
public class ConcreteItem : ITem
{
public ConcreteItem()
{
}
string Name { get; set; }
string Description { get; set; }
}
In my controller class i have following method
[HttpPost]
public IHttpActionResult ByGivenItems([FromBody] IEnumerable<Item> items)
{
//Do something here
}
The problem is when i send some content to the webservice (json formatted). The array is empty if i have the signature according to below
public IHttpActionResult ByGivenItems([FromBody] IEnumerable<Item> items)
But changing to
public IHttpActionResult ByGivenItems([FromBody] IEnumerable<ConcreteItem> items)
works. What should i do to let the json converter deserialize it to correct type? I am quite new in the C# world, so i need a good explanation how to do.
I have tested it through postman by sending some data.