this is the form group with nested array
this.InvoiceForm=this.fb.group({
InvoiceNumber:[''],
InvoicePath:[''],
Discription:[''],
EntryDate:[''],
InvoiceItem:this.fb.array([this.AddItemFormGroup()])
this method add form Group dynamically.
AddItemFormGroup()
{
return this.fb.group({
ItemName:[''],
ItemType:[''],
Quantity:[''],
Unit:[''],
Category:[],
Depo:[],
Comments:['']
})
}
the save method will call after submit method and I can access the form file but how I can access the nested from array which is InvoiceFrom in .net core web api.
Save()
{
const formData=new FormData();
formData.append('file',this.selectedFile,this.selectedFile.name);
formData.append('Discription',this.InvoiceForm.get('Discription').value)
formData.append('Date',this.InvoiceForm.get('EntryDate').value);
formData.append('Items',this.InvoiceForm.get('InvoiceItem').value);
this._http.post(environment.Item,formData,{
headers:new HttpHeaders(
{
'enctype':'multipart/form-data'
}
)
});
}
Server side code
[HttpPost,DisableRequestSizeLimit]
public async Task<ActionResult> AddItem()
{
var file = Request.Form.Files[0];
var description = Request.Form["Discription"];
var date = Request.Form["date"];
var items = Request.Form["items"];
return Ok();
}