Here is my view model:
[Serializable]
public class MyViewModel
{
public int VendorId { get; set; }
public HttpPostedFileBase SpreadsheetFile { get; set; }
public IEnumerable<Vendor> Vendors { get; set; }
}
I’m loading my view model up with data and passing it to a view and serializing it:
@Html.Serialize("MyModel", myViewModel)
but I’m getting this error
Type ‘System.Web.HttpPostedFileWrapper’ cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
I’m not sure how to mark something with the DataContractAttribute. Is there a way to mark the HttpPostedFileBase property as unserializeable?
Try marking it NonSerialized.