Form from Component HTML send this:
<form [formGroup]="Denuncia" (ngSubmit)="guardarDatos()"> <div class="form-group offset-md-1"> <label>(*) Tipo de Denuncia </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??