Naila Akbar
Naila Akbar

Reputation: 3358

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

In my Angular2 Application, I'm submitting a form and send data through POST API to dotnet core backend. I've created a new form, that is working fine with chrome, but on firefox, I'm receiving null in POST API parameter.

I'm all stuck what to search and how to?? I've checked every possible issue and didn't find anything, because App is working fine with chrome, all data is up to date and correct but a single form is not working on firefox.

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

My Endpoints are;

[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
}

my service on angular side

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

where this._SubmitIntimationUrl is "/api/Intimation/SaveIntimation", intiModel is object that I'm passing.

Controller function - 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);
  }
);

Data that is sending from service (Last place where I can check data)

Intimation Data

Upvotes: 2

Views: 289

Answers (2)

Ahmad Qasim
Ahmad Qasim

Reputation: 474

I went through same issue once, and It took almost a day to figure out the reason behind it,

do check your date pickers and its values, and make sure it is not null and its format is also correct. Because firefox is a bit strict in this matter and a litter change in datepicker makes it null.

hope it helps you.

Upvotes: 1

John H
John H

Reputation: 14640

The problem looks like it's because of the name of the parameter in your controller is different to that being passed up in the request.

In your controller, the parameter the framework is trying to bind to is called objCreateIntimation, but your request shows you're sending up objIntimation instead. As they have different names, the model binder has no idea that objIntimation should be bound to objCreateIntimation.

Give them both the same name, and that should fix it for you.

Upvotes: 2

Related Questions