So long story short I have a view where Im using
@using (Html.BeginForm("AddFormToOrder", "Form", FormMethod.Post, new { @id = "OrderForm", enctype = "multipart/form-data" }))
which will have a file upload where once I select the files and click an add to order button, the AddFormToorder will fire using the following info
models
public class Orders
{
public List<Forms> FormList { get; set; }
public Orders()
{
FormList = new List<Forms>();
}
}
public class Forms
{
public ICollection<IFormFile> Files { get; set; }
}
and in my controller I am doing this
public IActionResult AddFormToOrder(Forms form)
{
var Orders = JsonConvert.DeserializeObject<Orders>(HttpContext.Session.GetString("Shop_Orders"));
Orders.Forms.Add(form);
var serializedModel = JsonConvert.SerializeObject(Orders);
HttpContext.Session.SetString("Shop_Orders", serializedModel);
return RedirectToAction("Index", "Form");
}
This issue is that once that returns and goes to Index, I deserialize again but then get the following error
JsonSerializationException: Could not create an instance of type Microsoft.AspNetCore.Http.IFormFile. Type is an interface or abstract class and cannot be instantiated.
now if i add an order without files in it, everything works perfectly fine and this error never throws. I believe the issue is serializing the model with an IFormFile, but I have no idea how to get around it. Is it possible to serialize IformFile types?