开发者

"Not marked as serialized" error while the class was actually marked as Serialized with annotations

开发者 https://www.devze.com 2023-04-01 23:21 出处:网络
I have the following action methods in my controller. I have a multipage wizard scenario here. Now when I click next I get this "....type not marked as serialized" error message. I have seen

I have the following action methods in my controller. I have a multipage wizard scenario here. Now when I click next I get this "....type not marked as serialized" error message. I have seen posts related to same problem but couldn't get a solution for mine.

 public ActionResult startOpenJAccount()
                {
                        return View(vmJ);
                }

for this method the view is something like: 
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">


 <%using (Html.BeginForm("contReg")){ %>
    <%:Html.Serialize("vmJ", Model) %>
        
      <fieldset>
    <legend> Individual Personal Profile</legend>
       <table class="col1">

          <tr>
        <td><div class="display-label">Title</div></td>
        <td><div class="display-field"><%: Html.TextBoxFor(m=>m.开发者_开发知识库newMember.title) %></div></td>
        </tr> 

            <tr> 
        <td><div class="display-label">First Name</div></td>
        <td><div class="display-field"><%: Html.TextBoxFor(m=>m.newMember.FirstName )%></div></td>
           </tr> <tr>
 </table> 

        <div class="command"><input type="submit" name="next" value="Next" /></div>
        <div class="command"><input type="submit" name="cancel" value="Cancel" /></div>
    <%}%>
 </fieldset>

This page posts to the following action method:

 public ActionResult contReg(string next, string cancel)
        {
              if (next != null)
            {
                vmJ.members.Add(vmJ.newMember);   
                vmJ.newMember = new Individual();
                return RedirectToAction("displayRegInfo");
            }
            if (cancel != null)
                return RedirectToAction("displayRegInfo");
                return RedirectToAction("Index","default");
        }

Which for the click of Next returns this error. The class mentioned as "not marked as serializable" is not even included in the objects involved so far, instead was used later down the line in the same controller.


If this is an Entity Framework object you have two issues here

  1. I dont believe serializeable (it inherits from an entity object)
  2. Serializing it can result in a huge object

Use the POCO templates for Entity Framework. Mark your classes as serializable in the template .tt code or include [Serializable] through a partial class named the same as your class

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号