I am attempting to send an XML file from my Angular application to my ASP .Net Core controller. I would like the controller to receive the file and then deserialize it to a strongly typed list of objects. What is the correct way to go about this? I am currently receiving an error when the file is being deserialized which is stating 'Data at the root level is invalid. Line 1, position 1'. Below is what I have tried so far.
Controller:
[HttpPost("reconciliation")]
public async Task<IActionResult> SetReconciliation(IFormFile file)
{
List<ReconciliationExportCsv> records = new List<ReconciliationExportCsv>();
XmlSerializer serializer = new XmlSerializer(typeof(List<ReconciliationExportCsv>));
using (var reader = new StreamReader(file.OpenReadStream()))
{
records = (List<ReconciliationExportCsv>)serializer.Deserialize(reader);
}
var submitted = await _service.UploadReconciliationData(records);
return Ok();
}
}
Model:
public class ReconciliationExportCsv
{
public string or1 { get; set; }
public string exitStatus { get; set; }
public string vendorState { get; set; }
}
}
CSV: