My class:
public class LinkQueryOptions2
{
private string url { get; set; }
private bool isMobile { get; set; }
}
My API method:
[HttpPost]
[Route("")]
public void GenerateLink([FromBody] LinkQueryOptions2 data)
{
....
}
My fetch call in JavaScript:
const data = {
url: "{{urlOri}}",
isMobile: isMobile,
};
fetch("http://localhost:57266", {
method: "POST",
mode: "cors",
cache: "no-cache",
headers: {
Accept: "application/json;charset=UTF-8",
"Content-Type": "application/json;charset=UTF-8",
},
body: JSON.stringify(data),
});
In the backend I receive in my object the uninitialized values.
If I declare the properties of my class other than with private, it works – but I don’t understand why, any ideas?
public class LinkQueryOptions2
{
public string url { get; set; }
public bool isMobile { get; set; }
}