0

Can somebody help me with this mysterious problem? For example if the user inputs the value of the field called "Betrag" (amount) to lets say 0.03 in the C# MVC Controler api in the parameter of the Post method the value of the field "Betrag" will be 3 not 0.03.

     postForm(formValues: any): Promise<any> {
    const formData = this.prepareFormData(formValues, undefined);

    return this.http.post('/buchung/buchungspeichern', formData).toPromise();

  }

  prepareFormData(formValues, belegnrAbweisung: any) {
  formData.append('Buchung.Betrag', JSON.stringify(formValues.get('betrag').value);
  console.log(formData.get('Buchung.Betrag')) //OUTPUT: 0.03

  return formData;
 }

API

    [HttpPost("BuchungSpeichern")]
    [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
    [Authorize]
    public async Task<ActionResult> BuchungSpeichern([FromForm]BuchungSpeichernCommand command){
  ...
   }

      public class BuchungSpeichernCommand
{
    public BuchungCommandDto Buchung { get; set; }
}

public class BuchungCommandDto
{
    public double? Betrag { get; set; }
 }
Peter
  • 679
  • 1
  • 8
  • 19

0 Answers0