1

I got several pages (Mvc partial views) to load to a content div.

    $.ajax({
        url: '/Edit/'+tab,
        dataType: 'html',
        success: function (data) {
            $('#tab').html(data);
        }
    });

Of course there is a div in Html:

<div id="tab"></div>

The partial view can be successfully loaded into the tab div. But the partial views have their own knockout viewmodels. The binding is lost when loaded ajaxly.

So what is the correct way to load a page as well as its knockout binding?

Blaise
  • 21,314
  • 28
  • 108
  • 169
  • You're not *losing* the bindings, they're never applied in the first place. – CrimsonChris Jun 23 '15 at 15:31
  • possible duplicate of [Can you call ko.applyBindings to bind a partial view?](http://stackoverflow.com/questions/7342814/can-you-call-ko-applybindings-to-bind-a-partial-view) – CrimsonChris Jun 23 '15 at 15:31
  • I read that post. That post is `applyBindings` on the first load. Not after a partial view is ajaxly injected into the page. So when I do an `applyBindings()` in the `$.ajax(...).then()` call, I got `Error: You cannot apply bindings multiple times to the same element.` – Blaise Jun 23 '15 at 15:36
  • What element are you calling `applyBindings` on? It should be on the root element returned by your ajax. – CrimsonChris Jun 23 '15 at 16:20
  • possible duplicate of [get dynamically inserted html to work with knockoutjs](http://stackoverflow.com/questions/10826482/get-dynamically-inserted-html-to-work-with-knockoutjs) – CrimsonChris Jun 23 '15 at 16:23

0 Answers0