I have this Ajax:
$.ajax({
url: "/api/Values",
dataType: "json",
type: "POST",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
Id: "1", Name: "Name1", Family: "Family1"
}),
No I want to get data in controller so that I can save it to a text file with log4net. Currently I have written this code:
public void PostValues(Class1 cs)
{
var data = $"Id = {cs.Id}, Name = {cs.Name}, Family = {cs.Family}";
Log.Debug($"POST Request, value = {data}");
}
With model binding I can get data that is bound to class properties like above and then combine them like above. But I don't want to use this way because I have to go through all class properties. Is there any way to get data posted to controller as JSON? I'm sure that should be a way to get the following line in the controller:
Id: "1", Name: "Name1", Family: "Family1"