asp.net mvc 4 - MVC model binder issues when posting data from knockout -


I have a knockout model that I am trying to post to an MVC4 controller. A simplified version looks like this:

  varModelDel = function (id, name) {var self = this; Self.id = ko.observable (ID); Self.name = ko.observable (name); }; Var Entry = Function () {var self = this; Self.id = ko.observable (); Self.areas = ko.observableArray ([]); }; Var EntryModel = function () {var self = this; Self. Entry = new entry (); self.save = function () {$ .post ("/ edit", ko.toJS (self.entry), function (data) {...}}}}}}}   

If I add two models to my model, then this way:

  viewModel.entry.areas.push (new item modell (1, "A"); see Model.net. Race Push (New Item Model (2, "B"));   

and post it using viewModel.save I get two fields from Model Binder But there is no data in it (i.e. ID = 0, name = "").

After some research I found that I have been posting data like this I:

  id = 1 name = test area [0] [id] = 1 area [0] [name] = "a" field [1] [id] = 2 region [1] ] [Name] = "b"   

and that MVC expects:

  id = 1 name = test field [0] .id = 1 field [0] .name = "A" field [1] .id = 2 area [1] .name = "b"   

How do I expect to receive this post ?

Your model array so that you can wire your model And consequent to the controller Must send the mismatched string. You can try it:

  var EntryModel = function () {var self = this; Self. Entry = new entry (); // toJSON function produces JSON string representing the anti-model model var datatosend = K.O.JSON (self. Enter); self.save = function ($ .post ("/ edit", datatused, function (data) {...}}}}}}}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -