将 Javascript 对象转换为 C# 对象
本文关键字:对象 转换 Javascript | 更新日期: 2023-09-27 18:32:07
我正在设置Facebook画布付款,订单成功时需要回调。我有下面的代码,我正在使用 ajax 将回调数据传递给我的方法,以便我可以用它做一些事情。我只是不知道该将什么设置为方法的参数,以便我可以正确传递数据。
FB.ui(obj, function (data) {
$.ajax({
type: "GET",
dataType: "json",
contentType: "application/json",
url: "/Home/finishOrder",
data: myjsobject,
async: true
});
});
public class orderDetails
{
public string payment_id { get; set; }
public decimal amount { get; set; }
public string currency { get; set; }
public int quantity { get; set; }
public string request_id { get; set; }
public string status { get; set; }
public string signed_request { get; set; }
}
public void finishOrder(orderDetails orderDetails)
{
SendEmail.sendEmail(orderDetails.amount.ToString());
}
关闭,但试试这个:
FB.ui(obj, function (data) {
$.ajax({
type: "GET",
dataType: "json",
Content-type: "application/json",
url: "/Home/finishOrder",
data: myjsobject,
success: function(data) { alert('success'); }
});
});
public class orderDetails
{
public string payment_id { get; set; }
public decimal amount { get; set; }
public string currency { get; set; }
public int quantity { get; set; }
public string request_id { get; set; }
public string status { get; set; }
public string signed_request { get; set; }
}
public ActionResult finishOrder(orderDetails orderDetails)
{
SendEmail.sendEmail(orderDetails.amount.ToString());
return Json(new { Result = "e-mail sent" }, JsonBehavior.AllowGet);
}
注意:JS 对象必须与 C# 对象具有相同的属性名称。