Search code examples
c#visual-studiotypescriptform-data

How can I get a value which I receive over Request.Form


So in my Frontend I pass an Object which has a PersonId and a FormData object.

const formData = new FormData();

for (let file of files){
    formData.append(file.name, file,);
}
formData.append('currentId',this.UserId.toString());

const uploadReq = new HttpRequest('POST', 'https://localhost:5001/api/file',formData, {
      reportProgress: true,

});

The FormData Object I receive in my backend with this line:

var file = Request.Form.Files[0];

The question is how do I get the currentId value?

An approach of mine was this:

var PersonId = Request.Form.Keys;

But that gives me this back and I don't know how to get this value.

image of watch window


Solution

  • Define a variable of type StringValues:

    StringValues id;

    Then use that variable the following:

    Request.Form.TryGetValue("currentId", out id);