gpt4 book ai didi

c# - 如何修复 Viewstate 中表的序列化?

转载 作者:太空宇宙 更新时间:2023-11-03 12:38:12 25 4
gpt4 key购买 nike

我在我的页面中声明了一个 View 状态,如下所示:

public class TMP_RequestCourse
{
public int CourseCode;
public string CourseTitle;
public int PriorityID;
}
public TMP_RequestCourse T_RequestCourse
{
get
{
if (ViewState["TMP_RequestCourse"] == null)
return new TMP_RequestCourse();
return (TMP_RequestCourse)ViewState["insertMode"];
}
set { ViewState["TMP_RequestCourse"] = value; }
}

但是当页面加载时,我收到以下错误:

Type 'App.UI.Pages.EduRequestEdit+TMP_RequestCourse' in Assembly 'App.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

最佳答案

您应该添加 SerializableAttribute到你的类(class)。

[Serializable]
public class TMP_RequestCourse
{
public int CourseCode;
public string CourseTitle;
public int PriorityID;
}

When you create an object in a .Net framework application, you don't need to think about how the data is stored in memory. Because .Net framework takes care of that for you. However, if you want to store the contents of an object to a file, send an object to another process or transmit it across the network, you do have to think about how the object is represented because you will need to convert it to a different format. This conversion is called SERIALIZATION.

Reference

关于c# - 如何修复 Viewstate 中表的序列化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40103471/

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