made this webapi.
[HttpPost]
public void Post([FromBody] Models.IHero hero)
{
Models.Heroes heroes = new Models.Heroes();
heroes.AddHeroes(hero);
}
calling it from Postman.
https://localhost:44320/api/values?Id=1&Name=Shankar
but hero
received in method returns null
.
Interface:
public interface IHero
{
int Id { get; set; }
string Name { get; set; }
}
Update:
Converted IHero to Hero class
public class Hero
{
int Id { get; set; }
string Name { get; set; }
}
and used in the Post
method.
public void Post([FromBody] Models.Hero hero)
{
Models.Heroes heroes = new Models.Heroes();
heroes.AddHeroes(hero);
}
You have [FromBody] attribute, which means you need to pass data in the body of the Request, but not in Query params