ASP.NET 核心 API POST Firefox 参数始终为空

ASP.NET Core API POST parameter is always null from Firefox

在我的 Angular2 Application 中,我正在提交表单并通过 POST API to dotnet core backend 发送数据。我创建了一个新表单,它在 chrome 上运行良好,但在 Firefox 上,我在 POST API 参数 中收到空值.

我完全不知道要搜索什么以及如何搜索??我已经检查了所有可能的问题,但没有发现任何问题,因为应用程序在 chrome 上运行良好,所有数据都是最新且正确的,但 一个单一的表单在 firefox 上不工作

Can anyone help me out what to do? because I'm totally stuck and have no idea what to do??

我的端点是;

[HttpPost]
[Route("api/Intimation/SaveIntimation")]
public async Task<ActionResult> SaveIntimation([FromBody] ViewModelCreateIntimation objCreateIntimation)
{
    if (objCreateIntimation == null || objCreateIntimation.objIntimation == null)
            {

                return Ok("null received");
            }
           // remaining code
}

我在angular这边的服务

saveIntimation(intiModel) {
console.log(intiModel);
return this.httpClient.post<ViewModelResponse>(this.baseUrl + this._SubmitIntimationUrl, JSON.stringify(intiModel), { headers: this.configurations.getHeaderWithAuth() });
  }

其中 this._SubmitIntimationUrl"/api/Intimation/SaveIntimation"intiModel 是我传递的对象。

控制器功能 - Angular

this.intimationModel = this.admissionForm.value;
this.adminService.SubmitAdmissionIntimationService(this.createIntimationModel).subscribe(
  (response) => {
    this.responseModel = response;
    // further process
    },

  (error) => {

    this.notification.onClear();
    this.notification.onError(this.errorHandler.handleError(error).error, Constants.MESSAGE_ERROR);
  }
);

从服务发送的数据(我可以检查数据的最后一个地方)

问题看起来是因为您的控制器中的参数名称与请求中传递的参数名称不同。

在您的控制器中,框架尝试绑定的参数称为 objCreateIntimation,但您的请求显示您正在发送 objIntimation。由于它们的名称不同,模型绑定器不知道 objIntimation 应该绑定到 objCreateIntimation

给它们取一个相同的名字,这样应该可以解决问题。

我遇到过一次同样的问题,花了将近一天的时间才弄清楚背后的原因,

请务必检查您的日期选择器及其值,确保它不为空且格式也正确。因为 firefox 在这件事上有点严格,并且 datepicker 中的垃圾更改使其无效。

希望对你有帮助。