Asp.net mvc 在controlelr中将JSON对象发送到我的Ajax方法

Asp.net mvc 在controlelr中将JSON对象发送到我的Ajax方法,asp.net-mvc,json,jquery,Asp.net Mvc,Json,Jquery,我试图使用ajax在控制器中调用一个方法并传递一个对象。当涉及到变量时,我可以很好地做到这一点,但似乎不能使用对象。该方法被称为fine,但对象值始终为null。我也尝试过使用.toJSON方法,但未捕获到这个错误TypeError:Object函数(a,b){return new d.fn.init(a,b,g)}没有方法“toJSON”,是的,我包含了JSON2 以下是我迄今为止的尝试: var VoucherDetails = this.GetVoucherDetails();

我试图使用ajax在控制器中调用一个方法并传递一个对象。当涉及到变量时,我可以很好地做到这一点,但似乎不能使用对象。该方法被称为fine,但对象值始终为null。我也尝试过使用.toJSON方法,但未捕获到这个错误TypeError:Object函数(a,b){return new d.fn.init(a,b,g)}没有方法“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_凭证代码:

[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();
        }
    }

您可以将其作为JSON请求发送,该请求允许您发送任意复杂的对象:

var VoucherDetails = this.GetVoucherDetails();
$.ajax({
    url: '@Url.Action("GetVoucherPreviewTemplate", "Vouchers")',
    type: 'POST',
    contentType: 'application/json',
    data: JSON.stringify({ voucher: VoucherDetails }),
    success: function(result) {

    } 
});

如果包含了JSON2.js,那么您需要使用JSON.stringify()并将数据传递给它,以便在AJAX调用中序列化

你能给我看一下C级的耳鼻喉科凭证吗?到目前为止,您当前的代码看起来还不错。