0

I'm trying to serialize and deserialize the model with properties/attributes. But I'm unable to do the properties. How to serialize model with attributes?

Model:

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

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

Controller: Serialization:

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

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

Deserialization:

 viewModel= JsonConvert.DeserializeObject<viewModel>(Request.Cookies["cookie"].Value);
user3194721
  • 765
  • 4
  • 14
  • 47
  • Not sure I understand what your asking. When you serialize a model it creates a name/value pair for each property in the model. When you deserialize, it converts that back to the model (which has the attributes). –  Mar 11 '15 at 04:16
  • If i understand you correctly, this might give you a clue - http://stackoverflow.com/questions/21611674/how-to-auto-generate-a-c-sharp-class-file-from-a-json-object-string – vortex Mar 11 '15 at 09:50

0 Answers0