Every time I post to my Action, my ViewModel is not null, but all the values inside always are.
Where I have console.log, I can see perfect JSON being output to the console.
Any ideas?
Action:
public ActionResult Add(MyViewModel model)
{
//stuff
}
JS:
<script type="text/javascript">
var model = @Html.Raw(Viewbag.MyJSON);
var viewModelDetails = ko.mapping.fromJS(model);
this.addData = function() {
var data = ko.toJSON(viewModelDetails);
console.log(data);
$.post("/user/add", data, function(result){
//stuff
});
}
</script>
Model
public MyViewModel()
{
Game Game{get;set;}
}
EDIT:
WOW, I feel dumb, I had private set, so thats what it wasn't getting bound.
datais after you callko.toJSON?