I have view with button, and when the button is clicked partial view is loaded.(see code below), in some reason my .load function passes the object but Name is null and Id is 0
My View controller method:
public TestModel DoSomething()
{
TestModel m = new TestModel();
m.Name = "dosomething";
m.Id = 3;
return m;
}
My partial view Controller Action:
public ActionResult _Products(TestModel m)
{
return PartialView("_Products", m);
}
my jQuery:
$(document).ready(function () {
$(".example").click(function (e) {
e.preventDefault();
$.ajax({
url: "DoSomething/",
async: false,
success: function (data) {
$("#partialViewPlace").load("/Test/_Products", data);
}
});
});
});
When I debug the data parameter is passed but name is null and id is 0
datatoload()- that's the callback handler. Also making two AJAX requests seems redundant. Just make one and return the HTML you need from that. Also, removeasync: false. It's horrendous practice. If you check the console you'll even see the browser giving you a warning telling you not to use it.load( url [, data ] [, complete ] )- looks like it's the correct usage (although not one I'd use myself)public ActionResult _Products([FromBody] TestModel m)