i tried to pass multiple parameters using ajax in so many ways using "data:" but not all parameters are passed.
this is the OnPost PageModel method:
public JsonResult OnPostCreate(Product product, int id, string name)
{
return new JsonResult(new { success = true });
}
ajax:
function SaveMe() {
var product = {
ProductId: 1,
ProductName: 'Any',
UnitsInStock: 2,
Discontinued: true,
};
var id = 1;
var name = 'Product1';
var data = {};
data.product = product;
data.id = id;
data.name = name;
$.ajax({
url: `?handler=Create`,
method: "post",
contentType: "application/json",
headers: {
"XSRF-TOKEN": $('input:hidden[name="__RequestVerificationToken"]').val()
},
data: JSON.stringify(data)
})
.done(function (response) {
alert(response.success);
});
};
and i don't want use the parameters in the "url:" ajax like:
url: `?handler=Create&id=2&name=Product1`
can anyone help? thanks for all.