I have a model like so in javascript:
function SomeModel()
{
this.Id = ko.observable();
this.Name = ko.observable();
this.MetaData = {};
}
Then I need to send this to MVC so I can persist it in mongodb, however I dont know how is best to store the MetaData in the C# representation... as the model looks like:
public class SomeModel
{
public Guid Id {get;set;}
public string Name {get;set;}
public object MetaData {get;set;}
}
However it doesnt like binding the json object to the object, I am not sure if I should be using an ExpandoObject or something, as I am not really that fussed about accessing the data within the c# mvc service, it is only for plugins in the front end which can store their own data on an object for use later. So an example could be:
var someModel = new SomeModel();
someModel.MetaData.Bookmarks = [];
someModel.MetaData.Bookmarks.push({ location: 120, document: 23003032 });
So it could contain anything and sub objects, and like I say I just need to bung it into an object just as a transport mechanism for Mongo, which will save it fine as its schema-less.
Currently the models from JS are sent over ajax via Jquery, and auto binded in the controller then sent off to the repository.
== Edit ==
I have done a few minor tests with MVC4, and I can put an expando object within my models and have it populated, however it only seems to store 1 layer of data, so if I were to postback:
...,
MetaData: {
something: {
one: 1,
two: 2
}
},
...
I would end up with my expando object for the MetaData field knowing about the something field, but would not store any of the data below that first traversal, so is there any way to store the above other than turning it into a string of json to be stored?