2016-10-18 2 views
2

Ich habe einen Ansichtszustand in meiner Seite wie folgt erklärt:Wie behebt man die Serialisierung für die Tabelle in 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; } 
} 

aber wenn Seite geladen, ich folgende Fehler empfange:

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.

Antwort

1

Sie SerializableAttribute Ihre Klasse hinzufügen sollten.

[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

Verwandte Themen