I can't get ajax to transfer values to my asp.net razorpage handlers. It always receives null values on razorpage side. Otherway around it works and javascript isn't responding without errors.
The C# function "OnPost" gets called but has always null values as parameters.
What am I missing here? I looked at quite some examples and couldn't make it out. Am I missing something which has to be setup in the project? Please let me know if I should provide more code!
public class TestValues
{
public string test1 { get; set; }
public string test2 { get; set; }
public string test3 { get; set; }
}
public class Conf_Parity : PageModel
{
public static JsonResult OnPost(TestValues myString)
{
var test = myString;
return new JsonResult("");
}
}
}
var output = {
test1: 'hallo',
test2: 'peter',
test3: 'how are you'
};
console.log(output);
$.ajax({
type: "POST",
url: "Conf_Parity",
dataType: "json",
data: JSON.stringify(output),
contentType: "application/json; charset=utf-8",
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
failure: function (response) {
alert(response);
}
});
datatypetoapplication/json