I'm Trying to make pass a Json to a webservice in c#. But when i pass the Json, my function in c# doesn't save it(returns null). This is my c# code.
[HttpPost]
public JsonResult test(Product producto)
{
var model = producto;
return Json(new { success = true, result = "My usuario es " + model.Name});
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Category { get; set; }
}
and this is what i'm sending by postman
curl --location --request POST 'http://localhost/ws/test' \
--header 'Content-Type: application/json' \
--data-raw '{"Id":1,"Name":"abc","Category":"asd"}'
Why when i'm trying to get the producto.Name returns null?? Thanks you very much
Change your action header:
public JsonResult test([FromBody]Product producto)
{
...your code
}
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.