I’m trying to get an MVVM setup going for a ASP.NET MVC 4 application I’m working on. Recently I ran into the excellent presentation/code-sample from John Papa (which can be viewed here http://www.johnpapa.net/recent-presentation-on-spa-basics/).
He talks about having a jquery/knockout.js/breeze.js software stack, but only in the context of a Single Page Application (SPA).
Looking through the code- I see that a bootstrapper.js neatly sets up the bindings for all views.
ko.applyBindings(vm.sessions, $(app.viewIds.sessions).get(0));
ko.applyBindings(vm.speakers, $(app.viewIds.speakers).get(0));
ko.applyBindings(vm.session, $(app.viewIds.session).get(0));
If I were to have more cshtml files, to split the views in a more complicated application, how could I elegantly handle the boot strapping as navigation happens?
You can use several options (off the top of my head) to link in other views of html:
1) @Html.Partial
2) Knockout External Templating plugin
3) Custom AJAX to go grab the HTML for the views
4) Templating engine of your choice to grab it
5) RequireJS and its text plugin
6) Load them all in 1 page (icky for anything of size)
IF you have Knockout already,. you may want to use the Knockout external templating plugin. Its great for pulling in remote HTML. If you have require.js going already, the text plug in is very nice too.