My c# model
public class Student
{
public string id{get;set;}
[System.Text.Json.Serialization.JsonPropertyName("ref")]
public int @ref{get;set;}
}
My ASP.Net Core API method
[HttpPost]
public async Task<IActionResult> Get([FromBody] Student stu)
{
var reference = stu.@ref;
//Here stu.@ref is always 0.
//JSON to C# model conversion doesnt work
}
Following is the request body
{
"id":"74A",
"ref":41
}
C# doesnt allow to declare variable name "ref", so i declared as "@ref" and decorated it with JsonPropertyName("ref"). However json to c# model deserialsation doesnt map ref to @ref.
Any solution or work around.