KnockOutJS – Multiple ViewModels in a single View

Knockout now supports multiple model binding. The ko.applyBindings() method takes an optional parameter – the element and its descendants to which the binding will be activated. For example: ko.applyBindings(myViewModel, document.getElementById(‘someElementId’)) This restricts the activation to the element with ID someElementId and its descendants. See documentation for more details.

Getting “The JSON request was too large to be deserialized”

You have to adjust the maxJsonLength property to a higher value in web.config to resolve the issue. <system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength=”2147483644″/> </webServices> </scripting> </system.web.extensions> Set a higher value for aspnet:MaxJsonDeserializerMembers in the appSettings: <appSettings> <add key=”aspnet:MaxJsonDeserializerMembers” value=”150000″ /> </appSettings> If those options are not working you could try creating a custom json value provider … Read more

Can cleanNode() be used to clean binding?

ko.cleanNode is used internally by Knockout to clean up data/computeds that it created related to the element. It does not remove any event handlers added by bindings or necessarily understand if a binding made changes to the DOM. This can definitely cause problems like having multiple handlers attached to an element when it is subsequently … Read more

Catch error if iframe src fails to load . Error :-“Refused to display ‘http://www.google.co.in/’ in a frame..”

You wont be able to do this from the client side because of the Same Origin Policy set by the browsers. You wont be able to get much information from the iFrame other than basic properties like its width and height. Also, google sets in its response header an ‘X-Frame-Options‘ of SAMEORIGIN. Even if you … Read more

Can you call ko.applyBindings to bind a partial view?

ko.applyBindings accepts a second parameter that is a DOM element to use as the root. This would let you do something like: <div id=”one”> <input data-bind=”value: name” /> </div> <div id=”two”> <input data-bind=”value: name” /> </div> <script type=”text/javascript”> var viewModelA = { name: ko.observable(“Bob”) }; var viewModelB = { name: ko.observable(“Ted”) }; ko.applyBindings(viewModelA, document.getElementById(“one”)); ko.applyBindings(viewModelB, … Read more

jQuery UI datepicker change event not caught by KnockoutJS

I think that for the jQuery UI datepicker it is preferable to use a custom binding that will read/write with Date objects using the APIs provided by the datepicker. The binding might look like (from my answer here): ko.bindingHandlers.datepicker = { init: function(element, valueAccessor, allBindingsAccessor) { //initialize datepicker with some optional options var options = … Read more