asp.net mvc 3 - Pass Complex JSON Object to an MVC 3 Action -


i getting weird results while trying pass complex json object action in mvc 3.

the locations populated on action parameter model, name , location not.

if ko.tojs(testviewmodel), name , location there, locations blank???

i using knockout.js:

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")     } 

sending via jquery ajax:

$.ajax({             url: "/claimsauthority/home/testit",             type: "post",             data: ko.tojson(testviewmodel),             success: function (data, status, xhr) {                 //ko.applybindings(data);             }         }); 

mvc action:

<httppost()>         public function testit(model testmodel) actionresult             return json(model)         end function 

models:

public class testmodel      public property id integer     public property name string     public property locations icollection(of locationmodel)     public property position string   end class  public class locationmodel     public property id integer     public property name string     public readonly property displaytext string                     return string.format("({0}) {1}", id, name)         end     end property end class 

try setting content type application/json in ajax request:

$.ajax({     url: '/claimsauthority/home/testit',     type: 'post',     contenttype: 'application/json',     data: ko.tojson(testviewmodel),     success: function (data, status, xhr) {         //ko.applybindings(data);     } }); 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -