asp.net mvc - Button click data-bind is not working with knockout -
i cannot following piece of code fire button click call save. using asp.net mvc knockoutjs. new knockout , mvc. missing here? in advance.
cshtml
@section scripts { <script src="~/scripts/knockout-3.4.0.js"></script> <script src="~/scripts/knockout.mapping-latest.js"></script> <script src="~/customscripts/bookingviewmodel.js"></script> <script type="text/javascript"> var bookingviewmodel = new bookingviewmodel(@html.raw(data)); ko.applybindings(bookingviewmodel); </script> } <div class="content"> <button class="btn btn-primary pull-right" data-bind="click: save"><i class="fa fa-check"></i> save booking</button> </div>
bookingviewmodel.js
bookingviewmodel = function (data) { var self = this; ko.mapping.fromjs(data, {}, self); self.save = function () { $.ajax({ url: "/booking/save", type: "post", data: ko.tojson(self), contenttype: "application/json", success: function (data) { if (data.bookingviewmodel != null) { ko.mapping.fromjs(data.bookingviewmodel, {}, self); } } }); } }
Comments
Post a Comment