`
[HttpGet]
public List<studTB> StudentsList()
{
StudentEntities studentEntities = new StudentEntities();
return studentEntities.studTBs.ToList();
}
// POST api/values
[HttpPost]
public IEnumerable<studTB> Post([FromBody] studTB stud)
{
List<studTB> studentEntities = new List<studTB>();
studentEntities.Add(stud);
return studentEntities;
}
In Postman, your body is an array of studTB
objects, but in C#, your method parameter is a single studTB
object. Those need to match.
Either only post one at a time (as a JSON object, no array), or change the C# to accept a list.
public IEnumerable<studTB> Post([FromBody] List<studTB> studs)
{
List<studTB> studentEntities = new List<studTB>();
studentEntities.AddRange(studs); // change to Range to add multiple
return studentEntities;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.