javascript - Sending LIst<t> via ajax to complex model -
i know i've done before can't seem work.
i have following javascript;
$("#btntestvouchers").click(function () { var postdata = { "workplacegiverid": $(".wpgdropdownlist").val(), "frommemberid": $(".wpgfrommemberdropdownlist").val(), "tomemberid": $(".wpgtomemberdropdownlist").val(), "voucherexpirydate": $("#expirydatepicker").val(), "recipients": json.stringify("[{'firstname':'a','lastname':'b','email':'c','voucheramount':'d'}]") }; console.log(postdata); $.ajax({ type: "post", url: "/admin/testvouchercreationemails", contenttype: 'application/json; charset=utf-8', datatype: "json", data: json.stringify(postdata), success: function (d) { alert("ok"); }, error: function (xhr, textstatus, errorthrown) { alert("error:" + errorthrown); } }); });
in model have;
public class postdataobject { public int workplacegiverid { get; set; } public int frommemberid { get; set; } public int tomemberid { get; set; } public string voucherexpirydate { get; set; } public ienumerable<bulkvoucherrecipient> recipients { get; set; } } public class bulkvoucherrecipient { public string firstname { get; set; } public string lastname { get; set; } public string email { get; set; } public string voucheramount { get; set; } }
in controller have;
[httppost] public void testvouchercreationemails(postdataobject posteddata) { string g = ""; }
however when post, list of recipients empty.
if don't stringify list of recipients same result.
anyone know i'm doing wrong?
edit other values come through ok, list empty.
you don't need json.stringify
recipients.
"recipients": json.stringify("[{'firstname':'a','lastname':'b','email':'c','voucheramount':'d'}]")
remove json.stringify
form here , should work.
var postdata = { "workplacegiverid": $(".wpgdropdownlist").val(), "frommemberid": $(".wpgfrommemberdropdownlist").val(), "tomemberid": $(".wpgtomemberdropdownlist").val(), "voucherexpirydate": $("#expirydatepicker").val(), "recipients": [{'firstname':'a','lastname':'b','email':'c','voucheramount':'d'}] };
Comments
Post a Comment