This is the Ajax Call:
var selectedProductOptions = new Array();
$(".optionSelectionBox").each(function () {
selectedProductOptions.push($(this).val());
});
$.ajax({
url: "/Cart/AddItem",
type: 'post',
data: JSON.stringify({
productId : @Html.ValueFor(m => m.Product.Id),
selectedOptions : selectedProductOptions,
}),
success: function (data) {
if (data.IsSuccess) {
alert("test Hello Success");
}
alert("test HELLO Fail");
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown + "- Error");
}
});
And this is controller that is reciveing the call.
[HttpPost]
public JsonResult AddItem(string productId, List<string> selectedOptions)
{
//Code here
}
When I set a break point on the action it gets hit which is what I want but..... productId and selectedOptions are both NULL.
What Am I doing wrong?
selectedProductOptions? Can you give an example?