2

作業中のASP.NETMVC4アプリケーション用にMVVMセットアップを実行しようとしています。最近、John Papaの優れたプレゼンテーション/コードサンプルに遭遇しました(これはhttp://www.johnpapa.net/recent-presentation-on-spa-basics/で表示できます)。

彼は、jquery / knockout.js / breeze.jsソフトウェアスタックを使用することについて話しますが、これはシングルページアプリケーション(SPA)のコンテキストでのみです。

コードを見ると、bootstrapper.jsがすべてのビューのバインディングを適切に設定していることがわかります。

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));

より複雑なアプリケーションでビューを分割するために、より多くのcshtmlファイルがある場合、ナビゲーションが発生するときにブートストラップをエレガントに処理するにはどうすればよいですか?

4

2 に答える 2

4

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.

于 2013-01-11T00:09:55.360 に答える
1

それでもSPAとして使用できますが、すべての「ページ」を個別のcshtmlファイルに分割し、Html.Partialを使用してそれらをindex.cshtmlにロードします。

 @Html.Partial("_Substation")
 @Html.Partial("_Location")
 @Html.Partial("_Weather")
 @Html.Partial("_RealTimeValues")
 @Html.Partial("_EventView")

これらの文字列はすべて、個別のcshtmlファイルの名前ですが、それでもSPAです。

あなたがSPAを持ちたくないという別の理由がない限り?

于 2013-01-10T15:58:08.827 に答える