Refer to http://stackoverflow.com/questions/9610214/pass-complex-json-object-to-an-mvc-3-action
var testViewModel ={
Name: ko.observable("Joe Bob"),
Locations: ko.observableArray([
{ ID:1,Name:"Salem, OR"},
{ ID:2,Name:"Big Bear Lake, CA"},
{ ID:3,Name:"Big Bear City, CA"}
]),
Position: ko.observable("Manager")
}
public class TestModel {
public int ID {get;set;}
public string Name {get;set;}
public ICollection<LocationModel> Locations {get;set}
public string Position {get;set;}
}
public class LocationModel{
public int ID {get;set;}
public string Name {get;set;}
public string DisplayText
{
private set;
get {
return String.Format("({0}) {1}", ID,Name)
}
}
}
$.ajax({
url:'/ClaimsAuthority/Home/TestIt',
type:'POST',
contentType:'application/json',
data: ko.toJSON(testViewModel),
success: function (data, status, xhr){
//ko.applyBindings(data);
}
});