asp.net MVC序列化具有属性/属性的模型

时间:2015-03-10 23:29:01

标签: asp.net-mvc-4 serialization

我正在尝试使用properties / attributes序列化和反序列化模型。但我无法做这些属性。如何使用属性序列化模型?

型号:

   [Display(Name = "CreateCustomerView_FirstName")]
    public string FirstName { get; set; }

    [UIHint("DomainName")]
    [Display(Name = "CreateCustomerView_LastName")]
    public string LastName { get; set; }

控制器: 序列:

  cookie.Value = JsonConvert.SerializeObject(viewModel);
  //var serializer = new JavaScriptSerializer();
            //cookie.Value = serializer.Serialize(viewModel);

            //cookie.Value = viewModel.ToString();

反序列化:

 viewModel= JsonConvert.DeserializeObject<viewModel>(Request.Cookies["cookie"].Value);

0 个答案:

没有答案