0

Form from Component HTML send this:

 <form [formGroup]="Denuncia" (ngSubmit)="guardarDatos()"> <div class="form-group offset-md-1"> <label>(*) Tipo de Denuncia&nbsp;</label> <select class="combobox" id="Tipo_Denuncia" formControlName="Tipo_Denuncia"> <option value="">--Seleccione Opción--</option> <option [ngValue]="TipoDenuncia.cod_Tipo_Denuncia" *ngFor="let TipoDenuncia of TiposDenuncia">{{TipoDenuncia.nombre}}</option> </select> </div> <input [disabled]="!Denuncia.valid" type="submit" value="Generar" class="btn btn- success col-md-1 offset-md-1" /> </div> 

On Component.ts

 constructor(private denunciaservice: DenunciaService, private router: Router, private modalService: NgbModal, private formBuilder: FormBuilder) { this.Denuncia = this.formBuilder.group( { "Tipo_Denuncia": new FormControl("", [Validators.required]), } ); } 

Method call service

 guardarDatos() { if (this.Denuncia.valid == true) { this.denunciaservice.agregarDenuncia(this.Denuncia.value).subscribe(data => { if (data) { console.log(data); this.resultadoGuardadoModal = "ok"; } else this.resultadoGuardadoModal = "Not Ok!"; }); } } 

Service.ts:

 public agregarDenuncia(Denuncia: any): Observable<any> { var url = this.urlBase + 'api/Denuncia/guardarDenuncia/'; return this.http.post(url,Denuncia); } 

And declare class DenunciaDTO

Finally on the controller i dont recieve the parameter on the object DenunciaDTO

 [HttpPost] [Route("api/Denuncia/guardarDenuncia")] public int guardarDenuncia([FromBody] DenunciaDTO oDenunciaDTO) { int rpta = 0; try { using (M_VPSA_V3Context bd = new M_VPSA_V3Context()) { using (var transaccion = new TransactionScope()) { oDenuncia.CodTipoDenuncia = int.Parse(oDenunciaCLS2.Tipo_Denuncia!); } } rpta = 1; } catch (Exception ex) { Console.WriteLine(ex); rpta = 0; } return rpta; } 

When execute this oDenunciaDTO is null on the controller. What Happened??

1 Answer 1

1

Change [FromBody] to [FromForm], and your issue will be fixed.

Sign up to request clarification or add additional context in comments.

2 Comments

Tks, it works!!
@RomanSadowski Could you accept it as answer,tks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.