I have a form that contains a main view with a grid and several (bootstrap) modal forms. The modal forms are quite complex and take quite a while to download. Everything on the form is currently bound to a single knockout viewmodel. That viewmodel contains (among other things) arrays of dropdown items and subclasses of observable properties that are bound to the modal form elements.
Currently the entire form and data must download before the user can interact with the page. I'd like to break it down so that the loading flows in the following manner:
- Basic form elements and css
- VM is instantiated
- data for the grid downloads
- grid is bound to vm
- user can begin to interact
- elements of most commonly used modal form download
- modal form is bound to the VM
- repeat 6 & 7 for all modal forms
I've successfully been able to download the modal forms after the grid is bound as partial views, but now I get an error that "You cannot apply bindings multiple times to the same element." Is there a way to bind my partial views to the same viewmodel sequentially?
Here's my code that binds the base page to the vm. Note that it then calls loadQuoteModal which loads the Quote Modal Form.
$(document).ready(function () {
var vm = new ClientListViewModel();
ko.applyBindings(vm, document.getElementById("#baseClient"));
vm.loadQuoteModal();
});
Here's loadQuoteModal on my vm.
self.loadQuoteModal = function () {
var d = $.Deferred();
var xhr = $.get('/Home/QuoteModalForm');
xhr.done(function (partialViewResult) {
$("#LoadQuote").html(partialViewResult);
ko.applyBindings(this, document.getElementById("#quoteDiv"));
self.quoteLoaded = true;
});
return d;
}
And here's my page.
<div id="baseClient">
<div class="col-md-12" id="clientHeader">
//Many elements not relevent
</div>
<div class="col-md-12" id="clientDiv">
//Many elements not relevent
</div>
</div>
<div id="quoteDiv">
</div>