I'm using React to develop the front and C # Web APIs for back.
I'm trying to submit a form that has an input file, in the API I created a ViewModel to receive this data. Before submitting, I put form data in a FormData
, which is being filled correctly - I checked the console - however in the API the object always receives the empty values.
var data = new FormData();
data.append('IdMobileOperator', this.state.IdMobileOperator)
data.append('IdProductType', this.state.IdProductType)
data.append('TradeInDate', this.state.TradeInDate)
data.append('File', this.state.files)
$.ajax({
url: url,
type: 'POST',
data: { simCards: data },
processData: false,
success: function (response) {
//do something
}.bind(this),
error: function (response) {
//do something else
}
});
In the API, the action that receives the data is as follows:
[Route("Api/SimCard/Import")]
[HttpPost]
public async Task<HttpResponseMessage> ImportSimCard([FromBody]SimCardImportViewModel simCards)
{
//do something
}
As it stands, the action is encountered by the request, but the object simCards
has all the properties with no value - o when numeric, null when object, etc.