I am trying to pass an object using JavaScript to a controller.
I have used two parameters _amount
and _total
but the
values are empty in the controller on postback.
Any ideas why I can't get the values?
Also if I want to get the _data
which is an object containing different
values, how will I achieve it?
var itemsCart=toys.cart._items;
$.ajax({
url: '@Url.Action("SuccessView", "Home")',
type: 'POST',
data: itemsCart,
success: function (response) {
alert(response);
},
error: function (xhr, ajaxOptions, throwError) {
alert(xhr.responseText);
}
});
Controller:
public IActionResult SuccessView(List<ProductViewModel> products)
{
return View();
}
View Model:
public class ProductViewModel
{
public string _amount { set; get; }
public string _total { set; get; }
}
And a screenshot of the object from the website: