How to apply bindings to partialview within parent view that was already bounded? Or find workaround on how to overcome the need of the above...
I am using asp.net and I have main View that is doing staff with knockout ViewModelA
. Page has many divs (tabs), user is able to navigate via those tabs and all the time there is only one ViewModel (ViewModelA
). ViewModelA properties are populated within div1
,div2
,div3
and div4
. The simply html structure is like this:
<div id="mycontainer">
<div id="tab1">..<populate viewmodela properties>..</div>
<div id="tab2">...</div>
<div id="tab3">...</div>
<div id="tab4">...</div>
etc.
</div>
ko.applyBindings(ViewModelA);
It works fine, but now the requirements has changed: I have to insert partial view into one of those divs/tabs (inside #tab2
). This partial view loads its own knockout models using the following command:
ko.applyBindings(partialViewModel, document.getElementById("partial_view_container"));
In this case binding happens twice (when first time calling ViewModelA
binding, and second time when inserting partialview with its own binding staff). And this gives an error: "You cannot apply bindings multiple times to the same element".
How can I fix this? I know that for applyBindings
there is a second paramater that is the container within which bindings should be done, but in my case, I do not have one container for ViewModelA
, because ViewModelA
is populated withing different divs (tabs).