Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 491
samuel gast Avatar asked Sep 07 '25 07:09

samuel gast


1 Answers

Define a variable of type StringValues:

StringValues id;

Then use that variable the following:

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

like image 137
samuel gast Avatar answered Sep 09 '25 23:09

samuel gast