AndreyAkinshin / knockout-mvc

Power of Knockout.js for ASP.NET MVC
http://knockoutmvc.com
203 stars 125 forks source link

Lazy Load w/ ko.Html.Button #18

Closed DR9885 closed 1 year ago

DR9885 commented 11 years ago

It seems that after lazy load runs it stores the value of view model internal to the $.get, so when an action button is called it has no idea what "viewModel" is, so it throws a javascript error.

EX:

a data-bind="click : function() {executeOnServer(viewModel, '/api/Address/322');}" a data-bind="click : function() {executeOnServer(viewModel, '/api/Address/322');}"

<script type="text/javascript"> 

$(document).ready(function() {$.ajax({ url: '/api/Address/1', type: 'POST', success: function (data) { var viewModel = ko.mapping.fromJS(data); ko.applyBindings(viewModel); }, error: function (error) { alert('There was an error posting the data to the server: ' + error.responseText); } }); });