我正在尝试使用 ajax 在我的控制器中调用一个方法并传递一个对象。当涉及到变量时,我可以很好地做到这一点,但似乎无法使用对象来做到这一点。该方法调用正常,但对象值始终为空。我也尝试过使用 .toJSON 方法,但收到此错误 Uncaught TypeError: Object function (a,b){return new d.fn.init(a,b,g)} has no method 'toJSON' ,是的,我有 JSON2包括
到目前为止,这是我的尝试:
var VoucherDetails = this.GetVoucherDetails();
$.post("/Vouchers/GetVoucherPreviewTemplate", { "Voucher": VoucherDetails},
function (data) {
});
function GetVoucherDetails()
{
var teet = $("#Title").val();
return { Title: teet };
}
C#
[HttpPost]
public ActionResult GetVoucherPreviewTemplate(ENT_Voucher Voucher)
{
return Json("");
}
这是我的 ENT_Voucher 代码:
[Serializable]
public class ENT_Voucher : ENT_VoucherEntityBase
{
public int BusinessID { get; set; }
public int? SiteID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Code { get; set; }
public string Link { get; set; }
public DateTime StartDate { get; set; }
public DateTime ExpiryDate { get; set; }
public string ImageLink { get; set; }
public int Status { get; set; }
public ENT_Business BusinessDetails { get; set; }
public string VoucherTandC { get; set; }
public int Type { get; set; }
public string DaysRemaining { get; set; }
public int RequestCount { get; set; }
public bool IsPetoba { get; set; }
public ENT_Voucher()
{
this.BusinessDetails = new ENT_Business();
}
}