gpt4 book ai didi

c# - 序列化 View 模型时出错 : "Type ' System. Web.HttpPostedFileWrapper' 无法序列化。”

转载 作者:行者123 更新时间:2023-11-30 17:56:20 25 4
gpt4 key购买 nike

这是我的 View 模型:

[Serializable]
public class MyViewModel
{
public int VendorId { get; set; }

public HttpPostedFileBase SpreadsheetFile { get; set; }

public IEnumerable<Vendor> Vendors { get; set; }
}

我正在用数据加载我的 View 模型并将其传递给 View 并序列化它:

@Html.Serialize("MyModel", myViewModel)

但是我收到了这个错误

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.

我不确定如何使用 DataContractAttribute 标记某些内容。有没有办法将 HttpPostedFileBase 属性标记为不可序列化?

最佳答案

尝试标记它 NonSerialized .

[Serializable]
public class MyViewModel
{
public int VendorId { get; set; }

[NonSerialized]
public HttpPostedFileBase SpreadsheetFile { get; set; }

public IEnumerable<Vendor> Vendors { get; set; }
}

关于c# - 序列化 View 模型时出错 : "Type ' System. Web.HttpPostedFileWrapper' 无法序列化。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14271351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com