Javascript 为什么我的ajax请求向服务器发送空对象

Javascript 为什么我的ajax请求向服务器发送空对象,javascript,ajax,typescript,asp.net-core,xmlhttprequest,Javascript,Ajax,Typescript,Asp.net Core,Xmlhttprequest,我正在尝试使用XMLHttpRequest发出ajax请求。。。当调用processRequest方法时,我的MVC操作被命中,但是,对象属性值都为null Ajax类 MVC动作法 下面是我的对象、客户机对象和它在C中的等价物 JS对象 C对象 请尝试参数前面的FromBody属性: [HttpPost] public IActionResult SendEmail([FromBody] Enquiry emailEnquiry) { return Json("worked"); }

我正在尝试使用XMLHttpRequest发出ajax请求。。。当调用processRequest方法时,我的MVC操作被命中,但是,对象属性值都为null

Ajax类

MVC动作法

下面是我的对象、客户机对象和它在C中的等价物

JS对象

C对象

请尝试参数前面的FromBody属性:

[HttpPost]
public IActionResult SendEmail([FromBody] Enquiry emailEnquiry)
{
    return Json("worked");
}
试着跟随

xhr.send(JSON.stringify(this.data));

EmailInquiry对象中有什么?@tchelize我已经用EmailInquired更新了我的问题。你知道FromBody属性用于什么吗?这是用于模型绑定的。json对象应该绑定到请求主体。这在asp.net core中是json postswon所需要的。如果没有FromBody属性,不会发生同样的情况吗?仅在x-www-form-urlencoded请求上。
[HttpPost]
public IActionResult SendEmail(Enquiry emailEnquiry)
{
    return Json("worked");
}
    var emailEnquiry = {
        SenderName: txtNameVal,
        SenderEmail: txtEmailVal,
        SenderTelephone: txtTelephoneVal,
        SenderEnquiry: txtEnquiryVal,
        CaptchaResponse: ""
    };
public class Enquiry
{
    [Required(AllowEmptyStrings = false)]
    public string SenderName { get; set; }
    [Required(AllowEmptyStrings = false)]
    public string SenderEmail { get; set; }
    public string SenderTelephone { get; set; }
    [Required(AllowEmptyStrings = false)]
    public string SenderEnquiry { get; set; }
    public string CaptchaResponse { get; set; }
}
[HttpPost]
public IActionResult SendEmail([FromBody] Enquiry emailEnquiry)
{
    return Json("worked");
}
xhr.send(JSON.stringify(this.data));