Search code examples
asp.net-mvcasp.net-mvc-3knockout.jstemplatebinding

Multiple view binding with knokcout in asp.net mvc


I have a View xyz.cshtml

in which i render two partial views a and b . Now in xyz.cshtml page i have a button to switch view . But problems comes when i change view it doesn't apply binding on newly loaded view .

Thanks in advance .


Solution

  • If you load the partial views dynamically (I mean if they aren't both loaded on page load, but instead requested on button click) then Knockout will have 0 knowledge of those bindings.

    Off the top of my head I would basically have two view models and when you click the button and a new partial view is loaded in run ko.applyBindings on the loaded in markup.