javascript - knockout - pass child array with viewmodel data -


i have viewmodel following:

var viewmodel = new function () {        var self = this;      self.id = ko.observable();       self.currentorder = {          orderid: ko.observable(),        firstcropid: ko.observable(),        secondcropid: ko.observable(),          productdatalist: ko.observablearray()    };                        
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.0.0/knockout-min.js"></script>

i trying pass viewmodel.currentorder mvc controller follows:

self.saveorder = function () {        var url = '@url.action("saveorder", "orders")';        $.mobile.loading('show');          var productinfo = {};          (i = 0; < 3; i++) {          productinfo = { id: i, rate: + 11, variable: + 111 };          viewmodel.currentorder.productdatalist.push(productinfo);        }             $.ajax({            type: 'post',            url: url,            datatype: 'json',            data: viewmodel.currentorder,            traditional: true,            success: function (data, status) {                //success            },            error: function (xhr, ajaxoptions, thrownerror) {              $.mobile.loading('hide');            }            });        }; //save

the controller method looks this:

public function saveorder(vm ordersmodels.editviewmodel) jsonresult    dim o sales.order = getcurrentorder(vm.orderid)    o     .firstcrop = vm.firstcropid     .secondcrop = vm.secondcropid     .previouscrop = vm.previousfirstcropid      'code save order  end function 

ordersmodels.editviewmodel looks this:

public class editviewmodel    public property orderid guid    public property firstcropid integer    public property secondcropid integer     public property productdatalist list(of orderproducts) end class  public class orderproducts   public property id integer   public property rate decimal   public property variable decimal end class 

the controller getting data except vm.productdatalist nothing. tried sorts of things passing json.stringify(viewmodel.currentorder) data, adding contenttype: 'application/json; charset=utf-8' without luck.

how pass data controller?

this should work

$.ajax({        type: 'post',        url: url,        contenttype:'application/json; charset=utf-8',        datatype: 'json',        data:ko.tojson(self.currentorder),        success: function (data, status) {                    //success        },        error: function (xhr, ajaxoptions, thrownerror) {           $.mobile.loading('hide');        }  }); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -