Click here to Skip to main content
15,850,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900