Hello,
I'm using javascript with blazor and I'm having trouble binding a model that I pass in an Ajax request of type Post with my controller.
What I have tried:
@model AdminMenuResponse;
ajax({
type: 'POST',
url: 'Administration/UpdateUser',
data: { 'user': '@Html.Raw(JsonConvert.SerializeObject(Model))' },
error: function (xmlHttpRequest, textStatus, errorThrown) {
console.log(textStatus);
},
success: function (result) {
if (result && result.Success) {
}
else {
}
}
});
And in my controller I have:
public IActionResult UpdateUser(AdminMenuResponse user)
{
string errorMessage = string.Empty;
var dataResult = bObj.UpdateUser(user);
return null;
}
If I look at the browser console, the values go correctly in the json to the server, however C# can't bind them.
I also tried in the ajax function passing
data: '@Html.Raw(JsonConvert.SerializeObject(Model))'
, didn't work.
Any ideas? Thanks!