2016-10-18 30 views
2

我宣佈我的頁面視圖狀態一個像這樣的:如何修復Viewstate中的表序列化?

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.

回答

1

您應該添加SerializableAttribute到您的類。

[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

相關問題