Reputation: 1929
I am using .Net MVC with Entity Framework. In my Model Class I have these 2 properties:
public string Content { get; set; }
[NotMapped]
public dynamic DynamicContent { get { return Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(this.Content); } }
the "Content" contains a JSON string and the DynamicContent is a dynamic property based on the JSON string.
Can I modify the contents of the dynamic property? For example: I can read a value like this
DynamicContent.title
but how can I set its value from the controller?
DynamicContent.title = "myvalue"
does not work.
Upvotes: 0
Views: 202
Reputation: 357
You should be able to just set the value of the Content property as that is the value the DynamicContent property retrieves when you call the get method.
So instead of:
DynamicContent.title = "myvalue"
You would call:
Content = *the json representation of the content*
This would however need to be in JSON format as the DynamicContent getter DeSerializes it from JSON.
Upvotes: 1