MvcSerializer().Deserialize(serialized,SerializationMode....)
In asp.net mvc 3.0, I want to Deserialize and object which is stored in an input hidden filed.
Here is the Serializable class :
[Ser开发者_Python百科ializable]
public class RegistrationData { public string Name { get; set; } public string Email { get; set; } }
and the this is how i generate hidden field :
<%: Html.Serialize("regData", Model, Microsoft.Web.Mvc.SerializationMode.Signed)%>
but when I Deserialize it through following method, I get null values for my object :
var serialized = Request.Form["regData"];
if (serialized != null) { regData = (RegistrationData)newMvcSerializer().Deserialize(serialized,SerializationMode.Signed); }
Can any one help me please?
Model
public class RegistrationData
{
public string Name { get; set; }
public string Email { get; set; }
}
View
@using (Html.BeginForm())
{
@Html.HiddenFor(m=>m.Name)
@Html.HiddenFor(m=>m.Email)
}
Controller
public ActionResult Foo(RegistrationData form)
{
//do
//form.Name ->> get name
}
精彩评论