How to access multi dmnsnl array in web API Using angular

Jul 26 2019 9:18 AM

i am trying to upload an excel file and displaying the excel values in a html table. After that I will click on a button click- which will transfer the control to webapi with the values in the html table


I am using Angular and .net webapi

So i have written a service as follows

i am trying to upload an excel file and displaying the excel values in a table.

So i have written a service as follows

import { Injectable } from '@angular/core';

import { HttpHeaders } from '@angular/common/http';

import { HttpClient } from '@angular/common/http';

import { Observable } from 'rxjs';

@Injectable({

providedIn: 'root'

})

export class UploadServiceService {

constructor(private http: HttpClient) { }

url = 'http://localhost:xxxx/api/xyz/ExcelUpload'

UploadExcel(formData: FormData) {

let headers1 = new HttpHeaders();

headers1.append('Content-Type', 'multipart/form-data');

headers1.append('Accept', 'application/json');

const httpOptions = { headers: headers1 };

return this.http.post(this.url , formData, httpOptions)

}

}

 

Next I have called the service in component.ts which is as follows

getApprovals()

{

alert("from getapprovals");

let formData = new FormData()

formData.append('upload', this.arrayDisplay)

this.service.UploadExcel(formData).subscribe(result => {

this.message = result.toString();

});

}

Next I am trying to access the values of the array in webapi in the following way.

if (HttpContext.Current.Request.TotalBytes > 0)

{

foreach (string key in HttpContext.Current.Request.Form.AllKeys)

{

string value = HttpContext.Current.Request.Form[key];

}

}

But I am getting the value of HttpContext.Current.Request.Form[key] as

"[object Object],[object Object],[object Object],[object Object]"

Actually in the array I have 4 records…. Each record has multiple values internally.

How can I resolve this. Please help me


Answers (1)