I am having trouble to pass the serialized js object to controller and let the default model binder automtatically deserialize it into my object.
I can manually deserialize the value into my object, it's all fine. but I would like to know why it doesn't work.
Thanks
Here is my code snippet
js code
$.post('/Order/AddRecordAddHocStock2', { idPatient: $patientId, "orderItems": JSON.stringify($orderItems) }, function (data) {
//$("#recordingdialog").html(data).dialog("open");
var $dialog = $("#popup_dialog2");
$dialog.empty();
$dialog
.dialog({
bgiframe: true,
title: $title,
height: 700,
width: 650,
modal: true,
autoOpen: false,
resizable: false
});
$dialog.html(data).dialog("open");
});
Here is the post value get it from firefox
idPatient 72
orderItems [{"Id":0,"ProductName":"01870","Quantity":0,"StockOnHand":0,"MaxAllowance":12,"OrderTotal":0},{"Id":0,"ProductName":"01870","Quantity":0,"StockOnHand":0,"MaxAllowance":1,"OrderTotal":0}]
Here is my controller which I expected the orderItems should be automatically populate the value from the previous js object
[HttpPost]
public virtual ActionResult AddRecordAddHocStock2(long idPatient, List<OrderItemModel> orderItems)
{
var items = Request.Form["orderItems"];
//it's working if I manually deserialize the js object
var data = new JavaScriptSerializer().Deserialize(items,typeof(List<OrderItemModel>));
}