我想在我的控制器中使用ajax和传递一个对象来调用一个方法。当涉及到变量时,我可以很好地做到这一点,但似乎无法使用对象。该方法被称为罚款,但对象值始终为空。我也尝试使用.toJSON方法,但得到此错误未捕获TypeError:对象函数(a,b){返回新的d.fn.init(a,b,g)}没有方法'toJSON',是的,我有JSON2包括发送JSON对象到我的Ajax方法在一个controlelr
这是迄今为止我尝试:
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();
}
}
你还可以显示ENT_Voucher C#类吗?到目前为止你的代码看起来没问题 –