I use the helper Html.Serialize in one of my views, to serialize an object, and then I deserialize it again in my Controller using the MvcSerializer like this:
(RegistrationViewModel) new MvcSerializer().Deserialize(serializedObject);
This worked fine before, but after upgrading to MVC3 (And MVC3 Futures) The Deserialize method has changed so that it now has one more parameter: SerializationMode.
This I can set to either Signed or EncryptedAndSigned.
Regardless of which of these I use, I get an SerializationException asking me to verify that the data was serialized with the same mode I'm trying to deserialize with.
In my view, for some reason IntelliSense is not working for the Serialize method, so I don't know if this has gotten any additional overloads as well.
But the question is quite simply: How can I now, in MVC3, deserialize the data inside my controller that I have serialized inside the View with Html.Serialize?
EDIT - ADDED SOME CODE
From the Controller
private RegistrationViewModel registeredAccount;
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var serialized = Request.Form["regData"];
if (serialized != null)
{
registeredAccount = (RegistrationViewModel) new MvcSerializer().Deserialize(serialized, SerializationMode.EncryptedAndSigned);
TryUpdateModel(registeredAccount);
}
else
registeredAccount = (RegistrationViewModel)TempData["regData"] ?? new RegistrationViewModel();
}
public ActionResult Index()
{
if (Request.Form["nextButton.x"] != null)
return RedirectToAction("Details");
return View(registeredAccount);
}
From the view (The serialize call is at the start of the form)
@model VektNed.Models.RegistrationViewModel
...
<div class="BodyContainer RegistrationBody">
@using (Html.BeginForm()){
@Html.Serialize("regData", Model, SerializationMode.EncryptedAndSigned)
<div class="RegistrationGroup">
<p class="Description">e-posten din benyttes som brukernavn for å logge inn.</p>
<p><label for="Account_Email">e-post</label> @Html.EditorFor(x => x.Account.Email)<span class="ErrorMessage"></span></p>
<p><label for="RepeatEmail">gjenta e-post</label> <input type="text" name="RepeatEmail" id="RepeatEmail" /><span class="ErrorMessage"></span></p>
<p><label class="CheckboxLabel" for="ShareEmail">del din e-post med andre brukere. </label> @Html.EditorFor(x => x.Account.ShareEmail)</p>
</div>
<div class="RegistrationGroup">
<p><label for="Account_FirstName">fornavn</label> @Html.EditorFor(x => x.Account.FirstName)<span class="ErrorMessage"></span></p>
<p><label for="Account_LastName">etternavn</label> @Html.EditorFor(x => x.Account.LastName)<span class="ErrorMessage"></span></p>
</div>
<div class="RegistrationGroup">
<p><label for="Password">ønsket passord</label> @Html.EditorFor(x => x.Password)<span class="ErrorMessage"></span></p>
<p><label for="ConfirmPassword">gjenta passord</label> <input type="password" name="ConfirmPassword" id="ConfirmPassword" /><span class="ErrorMessage"></span></p>
</div>
<div class="RegistrationGroup">
<input class="NextAlone" name="nextButton" type="image" src="../../Images/button_next.png" alt="Neste" />
</div>
}
</div>
...