<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>News and Tutorials</title><link>http://datamoving.mvc-controls.com:80/blog</link><description>News and Tutorials</description><item><title>Data Moving SPA with a Context-Dependent Menu 2: Url based menu and SEO</title><link>http://datamoving.mvc-controls.com:80/blog/data-moving-spa-with-a-context-dependent-menu-2-url-based-menu-and-seo</link><description>&lt;p&gt;Data Moving SPA routing is not based on string Urls but&amp;nbsp; on the “virtualReference”&amp;nbsp; JavaScript class. Each instance of a virtual link contains all information needed to load a new view: view name, module containing the view, view input, and also an optional string property called “role” that&amp;nbsp; has the purpose of giving&amp;nbsp; different names to different instances of the same view. More specifically, the developer has the option to store each view in a &lt;u&gt;page store&lt;/u&gt;. This way when the user returns on a previous page he finds it in the same state he left it.: “roles” are needed to distinguish between different stored view instances that play different roles in the interaction with the user. &lt;/p&gt; &lt;p&gt;Usual links are substituted by virtual links containing a virtual references instead of a standard Urls. This solution avoid the burden of encoding all information needed to instantiate a view into a single Url. In fact, the main disadvantages of Url encoding are: &lt;/p&gt; &lt;ol&gt; &lt;li&gt;Once view properties have been encoded in a string that is hardcoded in the application sources it becomes difficult to&amp;nbsp; locate them during some re-engineering of the code.  &lt;li&gt;As the application grows a more complex encoding might be required, but locating and substituting Urls spread all over the code is an almost impossible task.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The substitution of Urls with virtual references is acceptable since, usually, we don’t need a SPA be indexed by search engines. However, now the support of search engines for SPAs and for JavaScript is increasing. More specifically:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;There is a standard protocol to substitute the dynamic pages of a SPA with static “page snapshots” produced by the server&amp;nbsp; whenever the SPA is visited by a search engine. See &lt;a href="https://developers.google.com/webmasters/ajax-crawling/?hl=iw&amp;amp;csw=1" target="_blank"&gt;here&lt;/a&gt; for more details.  &lt;li&gt;Now Google is able to run JavaScript, and to visit also SPA&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The above circumstances makes SPA attractive also for standard Web Sites that needs search engines indexing. For this kind of SPAs Urls play the same role they have in standard Web Applications. Namely, they furnish a way to reach all pages that compose the application and, together with all semantic tags, they help search engines to classify properly all pages.&lt;/p&gt; &lt;p&gt;The Url based &lt;a href="http://www.mvc-controls.com/free_software/ko_routing" target="_blank"&gt;ko.routing&lt;/a&gt; router was conceived as an attempt to keep the SEO advantages of standard&amp;nbsp; Urls while overcoming all disadvantages of keeping information encoded into strings (Urls).&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/free_software/ko_routing" target="_blank"&gt;ko.routing&lt;/a&gt; may compute dynamically all Urls starting from all parameters that must be encoded in the Urls themselves. This result is obtained by “inverting” the routing rules. The router &lt;u&gt;action&lt;/u&gt; method, and the related knockout.js &lt;u&gt;action&lt;/u&gt; binding accept the parameters to be extracted from an Url and build the Url that would yield exactly those parameters. They are very similar to the Asp.net Mvc &lt;a href="http://msdn.microsoft.com/en-us/library/dd505232(v=vs.118).aspx" target="_blank"&gt;Url.Action&lt;/a&gt; method, and have the same purpose of keeping the code completely independent from the routing rules.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/videos/releases_history" target="_blank"&gt;The 1.2 release of the Data Moving Controls suite&lt;/a&gt; added the support for ko.routing, and offers also SPA project templates based on ko.routing, namely: &lt;a href="https://drive.google.com/file/d/0B4MpO0a3KttDRG03cXhtblNOZUk/edit?usp=sharing"&gt;&lt;em&gt;SPA_Mvc5_ko.routing.vsix&lt;/em&gt;&lt;/a&gt; and &lt;a href="https://drive.google.com/file/d/0B4MpO0a3KttDYVdJaDFRWDd4bDg/edit?usp=sharing"&gt;&lt;em&gt;SPA_Mvc4_ko.routing.vsix&lt;/em&gt;&lt;/a&gt;.&amp;nbsp; &lt;/p&gt; &lt;p&gt;In this post I’ll revisit the &lt;a href="http://www.mvc-controls.com/blog/data-moving-spa-with-a-context-dependent-menu"&gt;Data Moving SPA with a Context-Dependent Menu&lt;/a&gt; tutorial with the new ko.routing based visual studio templates. The main difference is that now all menu items will contain actual links with actual Urls.&lt;/p&gt; &lt;h2&gt;Building the basic project&lt;/h2&gt; &lt;p&gt;You may repeat exactly the same steps of the &lt;a href="http://www.mvc-controls.com/blog/data-moving-spa-with-a-context-dependent-menu"&gt;Data Moving SPA with a Context-Dependent Menu&lt;/a&gt; tutorial till the “Defining a Menu to Navigate our SPAViews” section(not included), with the following two differences:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Select the &lt;u&gt;WebApi 2/Mvc 5/ko.routing Single Page Application&lt;/u&gt; project template instead of the &lt;u&gt;WebApi 2/Mvc 5/Single Page Application&amp;nbsp; template&lt;/u&gt;. &lt;strong&gt;Attention&lt;/strong&gt;: you must install both vsix in VS 2013 since only the second vsix contains the &lt;u&gt;SPAView&lt;/u&gt; and &lt;u&gt;SPAModule&lt;/u&gt; item templates.  &lt;li&gt;In all Page1.cshtml…Page5.cshtml dynamic JavaScript files supply an appropriate document title: vm._title = “View 1”…vm._title=”View 5”.&lt;/li&gt;&lt;/ol&gt; &lt;h4&gt;Defining a Menu to Navigate our SPAViews&lt;/h4&gt; &lt;p&gt;We will add the “Menu” SPAView to the &lt;em&gt;Basic&lt;/em&gt; module that is loaded as soon as the application starts, since our menu is needed also in the first loaded page.&amp;nbsp; Right click on the Views/Templates/Basic folder and add a new SPAView called: “Menu”:  &lt;p&gt;&lt;img src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/MenuAdded_thumb.png"&gt;  &lt;p&gt;In the previous tutorial we built the object tree containing all information to display in the menu on the server side and then we serialized it in JavaScript, in order to take advantage of the Data Moving &lt;em&gt;SimpleMenuBuilder&lt;/em&gt; class. Now we can’t do the same since we are going to build all menu Urls with the help of the JavaScript ko.routing &lt;u&gt;action&lt;/u&gt; method to keep our code independent from the client side routing rules.  &lt;p&gt;Accordingly as a first step&amp;nbsp; we define a JavaScript &lt;u&gt;menuBuilder&lt;/u&gt;&amp;nbsp; class to build our JavaScript object tree with an easy to use fluent interface. We may place this definition at the beginning of the MenuJs.cshtml file:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4f9588e2-ce58-4d50-8405-a1ca129b0b8e" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; menuBuilder(templateSelection) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; currLevel = [];&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; levels = [];&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.add = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (text, link, target, tSelection) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (mvcct.utils.isObject(link))&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;currLevel.push({&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;Text: text || &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;Params: link || &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;Link: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;+ko.routing.action(link),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;Target: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;UniqueIdentifier: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;Children: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;templateSelection:&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                            &lt;span style="background:#ffffff;color:#000000"&gt;tSelection || templateSelection&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;currLevel.push({&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;Text: text || &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;Params: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;Link: link || &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;Target: target || &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;UniqueIdentifier: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;Children: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;templateSelection:&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                            &lt;span style="background:#ffffff;color:#000000"&gt;tSelection || templateSelection&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.get = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; currLevel;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.down = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!currLevel.length) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; father = currLevel[currLevel.length - 1];&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;levels.push(currLevel);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;father.Children = currLevel = [];&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.up = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!levels.length) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;currLevel = levels.pop();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;u&gt;add&lt;/u&gt; method adds a new menu item. If just the Text field is passed we define a not clickable Item (typically a father menu item with sub items). If the link target is a string it is interpreted as an Url, otherwise, if it is an object it is interpreted as the set of parameters to be passed to the action method to yield the actual Url. Since all default routing rules patterns contain only the hash part of the Urls(something like #….)&amp;nbsp; and since strings starting with # are interpreted as custom JavaScript click handlers&amp;nbsp; instead of Urls by the menu control we add a leading “/”. The &lt;u&gt;Target&lt;/u&gt; parameter is taken into account only for string Urls, since it has no interpretation for the SPA Urls. &lt;/p&gt; &lt;p&gt;Each menu item stores both the computed Url and the original parameters used to compute it, since the parameters are needed to verify if a menu item Url refers to a SPAView&amp;nbsp; the current user has the right to visit or not. Moreover, the original parameters help in verifying if the current SPAView is an instance of the SPAView referenced by an item menu, with some possible input parameter more(simple string comparison between two Urls is able to verify only if both Urls reference&amp;nbsp; the same SPAView with exactly the same input).&lt;/p&gt; &lt;p&gt;The client template used to render each menu item is selected by calling a template selection function that receives the menu data item as argument. In order to ensure the maximum flexibility each menu item has its own template selection function. However if no item specific function is passed, the default template selection function passed as an argument to the &lt;u&gt;menuBuilder&lt;/u&gt; constructor is taken. &lt;/p&gt; &lt;p&gt;The &lt;u&gt;down&lt;/u&gt; method moves the fluent interface to the definition of the sub-items of the current item, and the &lt;u&gt;up&lt;/u&gt; method returns to the definition of the father item. &lt;/p&gt; &lt;p&gt;Finally the &lt;u&gt;get&lt;/u&gt; method yields the final object tree.&lt;/p&gt; &lt;p&gt;Now we are ready to build the Menu ViewModel:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b85481e8-cbc9-4c4a-9262-e10e7db00446" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="50" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; templateSelection = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (x) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (x.Children.peek()) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;Basic_MenuItem2&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; url = x.Link ? x.Link.peek() : &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (url &amp;amp;&amp;amp; url.charAt(0) != &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;@@&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &amp;amp;&amp;amp; url.charAt(0) != &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;#&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;Basic_MenuItem1&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;Basic_MenuItem0&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; menuItems = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; menuBuilder(templateSelection)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, { module: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Basic&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, view: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; })&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Page 1&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, { module: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;MenuExample&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, view: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Page1&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; })&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Page 2&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, { module: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;MenuExample&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, view: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Page2&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; })&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Private Area&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.down()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Page 3&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;{ module: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;MenuExample&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, view: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Page3&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; })&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Page 4&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;{ module: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;MenuExample&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, view: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Page4&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; })&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Page 5&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;{ module: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;MenuExample&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, view: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Page5&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; })&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.up()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;External Links&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.down()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Data Moving Controls&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;http://www.mvc-controls.com&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;knockout.js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;http://knockoutjs.com/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;_blank&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.up()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.get();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; viewModelContent = { Children: menuItems};&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;u&gt;viewModelContent&lt;/u&gt; is the put in place by the standard scaffolded code below:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:117b7b87-edf9-46b0-bc40-0a0c79b05179" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;vm.Content = ko.mapping.fromJS(viewModelContent);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;that creates all needed knockout observables an put the new modified model in the&amp;nbsp; ViewModel Content property.&lt;/p&gt; &lt;p&gt;The default template selection function selects 3 different templates: &lt;u&gt;Basic_MenuItem2&lt;/u&gt; for father items with children items, &lt;u&gt;Basic_MenuItem1&lt;/u&gt; for all items that do not contain an Url, and &lt;u&gt;Basic_MenuItem0&lt;/u&gt; for all items containing an Url. Each template name is obtained by chaining a base name declared with the .&lt;u&gt;TemplatesBaseName&lt;/u&gt; method of the Menu fluent interface with the the sequence number of the template defined with the Menu fluent interface. Below the content of the Menu.cshtml file:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a3fcb63f-7abc-4212-a8fa-c4d0594a9133" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@model &lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;MVCControlsToolkit.Controls.&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SimpleMenuItem&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; builder = Html.ExtendedClientMenuFor(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;m =&amp;gt; m.Children, m =&amp;gt; m.Link,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; { @class = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;mainmenu&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; });&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;HttpContext&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Current.Request.Browser.IsMobileDevice)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;builder = builder.ActiveOnlyOnClick();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;builder.Target(m =&amp;gt; m.Target)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.Radiuses(0.5f, 1f, 0.5f)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.ItemSelection(structurePathSelectClass: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;light-select&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.TemplatesBaseName(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Basic_MenuItem&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.TemplateSelector(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;function(x){return x.templateSelection(x);}&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.AddRowType()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.StartColumn(m =&amp;gt; m.Text)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.CustomColumnClass(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;GenericCssClasses&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.NoWrap)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.CustomTemplateFixed(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;TemplateType&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Display, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&amp;lt;text&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;a&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;href&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;javascript:;&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;item._D(m=&amp;gt;m.Text)&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;a&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;&amp;lt;/text&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.EndColumn()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.EndRowType()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.AddRowType()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.StartColumn(m =&amp;gt; m.Text)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.CustomColumnClass(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;GenericCssClasses&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.NoWrap)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.CustomTemplateFixed(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;TemplateType&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Display, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&amp;lt;text&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;item.LinkFor(m =&amp;gt; m.Text, m =&amp;gt; m.Link)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;&amp;lt;/text&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.EndColumn()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.EndRowType()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.AddRowType()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.StartColumn(m =&amp;gt; m.Text)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.CustomTemplateFixed(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;TemplateType&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Display, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&amp;lt;text&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;a&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;href&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;javascript:;&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;item._D(m=&amp;gt;m.Text)&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;a&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;&amp;lt;/text&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.EndColumn()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.ChildCollection(m =&amp;gt; m.Children)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;.EndRowType();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;builder.Render()&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;ExtendedClientMenuFor&lt;/em&gt; &lt;em&gt;Html&amp;lt;T&amp;gt;&lt;/em&gt; extension declares the root menu items collection, the property that contains the level 0 menu items, and the menu data item property that contains the “action” to execute when the menu item is selected.Then, &lt;em&gt;ExtendedClientMenuFor&lt;/em&gt;&amp;nbsp; returns a fluent interface to continue the menu configuration. The root Menu ul&lt;em&gt;&lt;/em&gt; tag contains the &lt;em&gt;mainmenu&lt;/em&gt; Css class&amp;nbsp; that defines some &lt;em&gt;&amp;lt;ul&amp;gt;&lt;/em&gt; and &lt;em&gt;&amp;lt;li&amp;gt;&lt;/em&gt; structural properties, and that removes underlining from all menu links.&lt;/p&gt; &lt;p&gt;The above definitions must be appended to the Content/Site.css file. You may experiment by changing some of them.  &lt;p&gt;As a default sub-menus appear when the mouse hover their father menu item, but If the client device is a mobile device the call to &lt;em&gt;ActiveOnlyOnClick()&lt;/em&gt; change this behavior, and sub-menus are open on “click” or “tap”.  &lt;p&gt;Then we declare which item property contains the target where to open links, and the various menu items radiuses (see the picture that shows the three radiuses &lt;a href="http://www.mvc-controls.com/controls/menu"&gt;here&lt;/a&gt; ).  &lt;p&gt;The way each menu item is rendered is defined by 3 templates, that are configured inside 3 &lt;em&gt;AddRowType()&lt;/em&gt;-&lt;em&gt;EndRowType()&lt;/em&gt; blocks. All templates have an unique column based on a custom template. The addition of the &lt;em&gt;GenericClasses.NoWrap&lt;/em&gt; Data Moving predefined Css class prevents menu item titles from wrapping. The &lt;em&gt;ChildCollection &lt;/em&gt;call in the last template causes the recursive rendering of all children sub items contained in the &lt;em&gt;Children&lt;/em&gt; property. All &lt;em&gt;AddRowType&lt;/em&gt; blocks define knockout client templates. Their names are obtained by adding the postfixes ‘0’ and ‘1’ and ‘2’ to the template base name “Basic_MenuItem” declared with &lt;em&gt;TemplateBaseName&lt;/em&gt;. It is good practice to give names of the type &lt;em&gt;&amp;lt;module name&amp;gt;_&amp;lt;a name&amp;gt;&lt;/em&gt; to all client templates used by controls declared inside SPAViews.  &lt;p&gt;The selection of the right template is performed by the template selection function declared with &lt;em&gt;TemplateSelector&lt;/em&gt;. In our case a function declared on line recalls the default template selection method previously defined in each menu data item.  &lt;p&gt;That’s enough to see the menu working! Now you may run the application and enjoy your Menu!  &lt;h4&gt;Adapting the Menu to the Current Page and to the Current Logged User&lt;/h4&gt; &lt;p&gt;Now, our last objective is to adapt the menu to the logged user and to the actual SPAView that is in the main host. More specifically:  &lt;ul&gt; &lt;li&gt;Each time the user changes the menu must display just the items the new user has the right to access, that is: if all sub-menus of a father menu item&amp;nbsp; are not visible and if the father menu item itself doesn’t connect to a SPAView the user may access, the father menu item&amp;nbsp; must be invisible  &lt;li&gt;The menu item that connects to the actual SPAView that is in the main host must appear in a “selected state”.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Both requirements may be achieved by letting the content ViewModel of our menu implements an interface, say,&lt;em&gt;IContextDependent&lt;/em&gt; with two methods:  &lt;ul&gt; &lt;li&gt;authorize(), that adapts the SPAView (our menu SPAView) to the authorizations of the current user.  &lt;li&gt;select(x), that informs the SPAView (our menu SPAView) that the SPAView x is currently in the main host. Where x is a string with the same format of the Link property of our menu data items. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;In general we may handle several SPAViews that implements the &lt;em&gt;IContextDependent&lt;/em&gt; interface in a modular way as follows:  &lt;ol&gt; &lt;li&gt;We define a &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; resource handler with methods to register and unregister &lt;em&gt;IContextDependent&lt;/em&gt; implementations for being properly handled by the application.  &lt;li&gt;Each time a SPAView that implements &lt;em&gt;IContextDependent&lt;/em&gt;, is loaded it registers itself to the &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; resource handler, and then it unregisters itself when it is unloaded.  &lt;li&gt;Whenever the current user changes, the &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; resource handler is notified and calls the authorize&lt;em&gt;()&lt;/em&gt; method of all registered &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp;&amp;nbsp; implementations.  &lt;li&gt;Whenever the current SPAView in the main host changes the the &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; resource handler is notified and calls the&lt;em&gt; select(x)&lt;/em&gt; method of all registered &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp;&amp;nbsp; implementations.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;We may define the class that implements the &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; resource handler in the Views/Templates/Application/MainJs.cshtml file next to the definition of the &lt;em&gt;uiBlockInterface&lt;/em&gt; class:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:74ee16c5-210c-460c-b67e-9602d59c0394" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; iContextDependentHandler = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; registrations = [];&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.register = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (x) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;registrations.push(x);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.unregister = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (x) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; index = -1;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;for&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; i = 0; i &amp;lt; registrations.length; i++) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (registrations[i] == x) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;index = i;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;break&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (index &amp;gt; -1) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;array.splice(index, 1);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.select = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (x) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;for&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; i = 0; i &amp;lt; registrations.length; i++) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; item = registrations[i];&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (item.select) item.select(x);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.authorize = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;for&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; i = 0; i &amp;lt; registrations.length; i++) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; item = registrations[i];&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (item.authorize) item.authorize();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp; &lt;p&gt;Then, we add an instance of this class to the &lt;em&gt;applicationModel.interfaces&lt;/em&gt; property, so that it is available within the &lt;em&gt;applicationModel&lt;/em&gt; itself and to all SPAViews:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8b2cad2e-96fe-4598-865b-a8d65336d43c" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;applicationModel.interfaces.uiBlock = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; uiBlockInterface();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;applicationModel.interfaces.contextHandler = &lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;//&amp;lt;-add here&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; iContextDependentHandler();&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;IContextDependent.select&lt;/em&gt; method must be called each time the router selects a new SPAView is placed in the application main host. Accordingly, let open the Views/Templates/Application/RoutingJs.cshtml file that contain the definition of all routing rules and let add the .&lt;u&gt;select&lt;/u&gt; call immediately after the the start of a new SPAView loading:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f58b46b1-2990-4555-be77-1ed2603f4075" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;ko.routing.defaultAction(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (obj, level, hasChildren) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;vl = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; mvcct.ko.dynamicTemplates&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;.virtualReference(obj.module, obj.view, obj.role);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;vl.input = obj;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;applicationModel.MainContent(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.defaultPageStore.get(vl));&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;setTimeout(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;// &amp;lt;-- added line&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;applicationModel.interfaces.contextHandler.select(obj)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;ko.routing.mainRouter = applicationModel.mainRouter =&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; window.ko.routing.router()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.route(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;#!/:module/:view&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.notFound({ module: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Basic&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, view: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;NotFound&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; });&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;})();&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Since all default routing rules use the default action function our call must be placed only there. The default action uses the view, module and role parameters to create a virtual reference and then passes all parameters extracted by the Url as input to the SPAView (Input property of the virtual reference). Then the virtual link is used to fetch the SPAView from the default page store. If an instance of the required SPAView with the specified role(if any) is already stored it is returned, otherwise a new fresh copy is created&amp;nbsp; (and stored) by the page store possibly downloading the required module from the server. Finally, the newly fetched SPAView is inserted in the main page host (applicationModel.MainContent).&lt;/p&gt; &lt;p&gt;The .&lt;u&gt;select&lt;/u&gt; call is wrapped inside a &lt;u&gt;setTimeOut&lt;/u&gt; to ensure it be executed only after that all &lt;u&gt;IContextDependent&lt;/u&gt; implementations (in our case just the menu) have been loaded when the SPA starts.&lt;/p&gt; &lt;p&gt;The right place where to call &lt;em&gt;IContextDependent.register&lt;/em&gt; is the &lt;em&gt;processInput&lt;/em&gt; method that is called each time a SPAView is loaded, while the right place to call &lt;em&gt;IContextDependent.unregister&lt;/em&gt; is the &lt;em&gt;beforeRemove&lt;/em&gt; method that is called before the SPAView is unloaded:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:26006c62-0de6-4d63-b302-1c76109904d3" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;vm.processInput = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (nodes) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@*&lt;/span&gt;&lt;span style="background:#ffffff;color:#006400"&gt; Code here is executed each time the page is loaded.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#006400"&gt;Virtual page inputData must be processed here &lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;*@&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;vm._interfaces.contextHandler.register(vm.Content);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;modifyDomOnLoad(vm, nodes);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;vm.beforeRemove = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@*&lt;/span&gt;&lt;span style="background:#ffffff;color:#006400"&gt; Insert here clean up code to be  executed&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#006400"&gt;when the page is unloaded&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;*@&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;vm._interfaces.contextHandler.unregister(vm.Content);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;cleanupDomOnUnload(vm);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now our &lt;em&gt;vm.Content&lt;/em&gt; ViewModel must implement&amp;nbsp; the &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; interface. You may place the interface definition immediately before the &lt;em&gt;vm.processInput&lt;/em&gt; method definition:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f72b13ef-0da5-4ae2-8d45-5cab9fe50b5e" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;vm.Content.select = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (obj) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!obj) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (currentSelected)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.html.menu.selected(currentSelected, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;currentSelected = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; res =&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;selectMenu(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;ko.utils.unwrapObservable(vm.Content.Children),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;obj);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!res &amp;amp;&amp;amp; currentSelected)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.html.menu.selected(currentSelected, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;currentSelected = res;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;vm.Content.authorize = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;authorizeMenu(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.authorizationManager(),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;vm.Content.Children);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;vm.Content.authorize();&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp; &lt;p&gt;Both methods call two private recursive functions that traverse the menu data items hierarchy to do their job. They are exactly the same of the ones defined in the &lt;a href="http://www.mvc-controls.com/blog/data-moving-spa-with-a-context-dependent-menu"&gt;Data Moving SPA with a Context-Dependent Menu&lt;/a&gt; tutorial.  &lt;p&gt;The &lt;em&gt;currentSelected&lt;/em&gt; private variable contains the menu data item that is currently selected, if any, otherwise, &lt;em&gt;null&lt;/em&gt;. If a &lt;em&gt;null&lt;/em&gt; action is passed, &lt;em&gt;currentSelected&lt;/em&gt; is set to &lt;em&gt;null&lt;/em&gt; and any previously selected menu item is unselected by calling &lt;em&gt;mvcct.html.menu.selected(currentSelected, false)&lt;/em&gt;.  &lt;p&gt;Otherwise the reclusive &lt;em&gt;selectMenu&lt;/em&gt; function tries to locate a menu data item matching the &lt;em&gt;action&lt;/em&gt; string. If such a data item is found the menu item it is bound to is set in the selected state by calling: &lt;em&gt;mvcct.html.menu.selected(item, true)&lt;/em&gt;and the data item itself is returned in the &lt;em&gt;res&lt;/em&gt; variable, so it may substitute the previous &lt;em&gt;currentSelected&lt;/em&gt;. If the &lt;em&gt;selectMenu&lt;/em&gt; recursive search fails, &lt;em&gt;null&lt;/em&gt; is returned in &lt;em&gt;res&lt;/em&gt;, and any previously selected item is unselected by calling &lt;em&gt;mvcct.html.menu.selected(currentSelected, false)&lt;/em&gt;.  &lt;p&gt;The authorize method immediately calls the recursive private function &lt;em&gt;authorizeMenu&lt;/em&gt; passing it the current authorization manager, and the level 0 menu data items. The &lt;em&gt;authorizeMenu&lt;/em&gt; function traverses the menu data items hierarchy and checks possible links to SPAView against the authorization manager to verify if the SPAView may be accessed by the current user. In case the SPAView referred by a menu data item cannot be accessed by the user, the data item rendering is prevented by setting its &lt;em&gt;_destroy&lt;/em&gt; property to &lt;em&gt;true&lt;/em&gt;. If a menu item x has the only purpose of showing its children sub-items, and if all its children have &lt;em&gt;_destroy&lt;/em&gt; set to &lt;em&gt;true&lt;/em&gt; also the &lt;em&gt;_destroy&lt;/em&gt; property of x is set to true&lt;em&gt;&lt;/em&gt;, since it is completely un-useful.  &lt;p&gt;The private functions &lt;em&gt;selectMenu&lt;/em&gt;&amp;nbsp; and &lt;em&gt;authorizeMenu&lt;/em&gt; may be placed in the read-only private members area immediately before the &lt;em&gt;mvcct.core.moduleResult&lt;/em&gt; call. They differ from the analogous function of the &lt;a href="http://www.mvc-controls.com/blog/data-moving-spa-with-a-context-dependent-menu"&gt;Data Moving SPA with a Context-Dependent Menu&lt;/a&gt; tutorial only in the way references to SPAViews are compared:   &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ac3969d2-a1fa-453c-aeef-8194bdc74435" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; selectMenu(children, obj) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;for&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; i = 0; i &amp;lt; children.length; i++) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; item = children[i];&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; toTest = ko.utils.unwrapObservable(item.Params);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; match = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;for&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; prop &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; obj) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!toTest || ko.utils.unwrapObservable(obj[prop])&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;!= ko.utils.unwrapObservable(toTest[prop])) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;match = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;break&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (match) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.html.menu.selected(item, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; item;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; iChildren = ko.utils.unwrapObservable(item.Children);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (iChildren) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; child = selectMenu(iChildren, obj);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (child) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; child;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; authorizeMenu(authorizationManager, obsChildren) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; children = ko.utils.unwrapObservable(obsChildren);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!children || children.length == 0) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; hasChildren = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; aChange = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;for&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; i = 0; i &amp;lt; children.length; i++) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; item = children[i];&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; action = ko.utils.unwrapObservable(item.Params);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; virtualLink = action;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; authorized = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (virtualLink) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;authorized =&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;!authorizationManager.verifyAuthorization(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;action&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; authorized = ko.utils.unwrapObservable(item.Link);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;authorized = authorized || &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (authorized) authorized = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; childrenAuthorized =&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;authorizeMenu(authorizationManager, item.Children);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;authorized = authorized || childrenAuthorized;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ((item._destroy || &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) != !authorized) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;item._destroy = !authorized;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;aChange = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (item._destroy) mvcct.ko.unfreeze(item);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (authorized) hasChildren = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (aChange) obsChildren.valueHasMutated();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; hasChildren;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;It is worth to point out that each time we make invisible a menu item we call the &lt;em&gt;mvcct.ko.unfreeze&lt;/em&gt; to release any possible cached template, since most of Data Moving controls cache templates instances to improve performance.&lt;/p&gt; &lt;p&gt;The &lt;u&gt;selectMenu&lt;/u&gt; function compares the set of parameters of each menu item with the set of parameters that identifies the current SPAView. If the current SPAView contains some parameters more, the comparison is considered successful since those parameters are further specifications of the input contained in the menu item.&lt;/p&gt; &lt;p&gt;Now the context dependent menu is ready. Whenever you navigate to a SPAView that is referenced in a menu item that menu item will become visible and will appear in a selected state:&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/SelectedMenu_thumb.png"&gt;&lt;/p&gt; &lt;p&gt;If a permanently opened sub-menu is not acceptable in your application, you may customize the Css class that is added to all menu items on the path to the selected item by calling the &lt;em&gt;ItemSelection&lt;/em&gt; method of the menu fluent interface. In the example below, a yellow border is added to all items on the path to the selected&amp;nbsp; item instead of leaving them permanently in the opened state:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ad2a9950-d580-4dbe-80e3-028c2af4bbce" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Radiuses(0.5f, 1f, 0.5f)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.ItemSelection(structurePathSelectClass: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;light-select&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;//&amp;lt;-&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1ff90de5-d7ae-46b5-a562-8a7b8477e119" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#800000"&gt;.light-select{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;border&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;:&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;2px&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;solid&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;yellow&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;!important&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp; &lt;p&gt;In this case the “selected color” on the menu item linking to “Page 4” becomes visible only if you hover the yellow-border “private area”: &lt;p&gt;&lt;img src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/AlternateSelect.png"&gt; &lt;p&gt;You may also add a &lt;em&gt;breadcrumb&lt;/em&gt; and modify the menu &lt;em&gt;select&lt;/em&gt; method to update the breadcrumb, too.  &lt;p&gt;&lt;strong&gt;That’s all for now!&lt;/strong&gt; The full code is available in the “ContextDependentMenu_ko_routing” file that may be found &lt;a href="https://drive.google.com/file/d/0B4MpO0a3KttDYnF4b1A1MmI2QUU/edit?usp=sharing" target="_blank"&gt;here&lt;/a&gt; and in the &lt;a href="https://datamovingexamples.codeplex.com/releases"&gt;Data Moving Plugin Examples Codeplex site download&amp;nbsp; area.&lt;/a&gt; The Visual studio solution must be activated by installing the&amp;nbsp; DataMovingPlugin5Examples.x.x.x.nupkg file you get with the product.  &lt;p&gt;&lt;strong&gt;Francesco&lt;/strong&gt;&lt;/p&gt;</description><pubDate>Wed, 25 Jun 2014 11:10:54 GMT</pubDate><guid isPermaLink="true">http://datamoving.mvc-controls.com:80/blog/data-moving-spa-with-a-context-dependent-menu-2-url-based-menu-and-seo</guid></item><item><title>Implementing an Owin Globalization Module with Katana</title><link>http://datamoving.mvc-controls.com:80/blog/implementing-an-owin-globalization-module-with-katana</link><description>&lt;h2&gt;Introduction.&lt;/h2&gt; &lt;p&gt;&lt;a href="http://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana" target="_blank"&gt;Owin&lt;/a&gt;&amp;nbsp; became popular in the Mvc arena with the Mvc5 release whose authentication and authorization components are implemented as Owin &lt;em&gt;application delegates&lt;/em&gt;. &lt;/p&gt; &lt;p&gt;An Owin based application is implemented as a pipe composed of&amp;nbsp; transformation modules, the middleware, and application modules. Roughly, the middleware components are equivalent to &lt;a href="http://msdn.microsoft.com/en-us/library/bb398986(v=vs.100).aspx" target="_blank"&gt;Asp.net modules&lt;/a&gt;, while application components are equivalent to &lt;a href="http://msdn.microsoft.com/en-us/library/bb398986(v=vs.100).aspx" target="_blank"&gt;Asp.net Handlers&lt;/a&gt;. Both application components, and middleware are implemented as &lt;em&gt;application delegates&lt;/em&gt;:&lt;/p&gt; &lt;p&gt;&lt;em&gt;Func&amp;lt;IDictionary&amp;lt;string, object&amp;gt;, Task&amp;gt; &lt;/em&gt;&lt;/p&gt; &lt;p&gt;That is, as functions that take&amp;nbsp; a dictionary containing information extracted from the client request and provided by other application delegates as input and that return a &lt;em&gt;task&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;The use of tasks avoids that the block of an &lt;em&gt;application delegate&lt;/em&gt; waiting for a long-running operation might block the whole Owin pipeline thread.&lt;/p&gt; &lt;p&gt;While &lt;em&gt;Owin&lt;/em&gt; is an abstract specification &lt;em&gt;Katana&lt;/em&gt; is a concrete implementation. &lt;em&gt;Katana&lt;/em&gt; architecture is based on 4 logical layers: the middleware and the application layers that I already mentioned, the host, and the web server.&lt;/p&gt; &lt;p&gt;The host is responsible for creating and orchestrating all underlying processes, and for creating and connecting the pipeline composed by the middleware and the application, while the web server is responsible for opening a network socket, listening for requests, and sending them through the Owin pipeline after having filled the initial &lt;em&gt;IDictionary&amp;lt;string, object&amp;gt;&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;We may&amp;nbsp; either use&amp;nbsp; IIS/Asp.net to implement the host/Web Server pair or we may&amp;nbsp; launch a custom host process that calls a web server implementation. &lt;/p&gt; &lt;p&gt;Thus, one of the advantages of implementing our Globalization module as Owin middleware instead of an Asp.net module is that we may use it also with custom-hosted applications(typically &lt;em&gt;WebApi&lt;/em&gt; and &lt;em&gt;SignalR&lt;/em&gt; custom-hosted applications). Moreover Katana updates are released as Nuget packages that are independent of the Asp.net stack, so we may benefit of more frequent updates and improvements.&lt;/p&gt; &lt;p&gt;Finally, the implicit use of Tasks in the Owin pipeline furnishes an easy way to improve performance, without any supplementary programming effort.&lt;/p&gt; &lt;p&gt;Everything is needed to define and use &lt;em&gt;Katana&lt;/em&gt; Middleware is contained in the dlls:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Owin.dll, that contains the abstract definition of Owin  &lt;li&gt;Microsoft.Owin, that contains Katana core  &lt;li&gt;Microsoft.Owin.Host.SystemWeb that contains a Katana server able to interact with Asp.net pipeline.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;You may get everything by installing the &lt;em&gt;Microsoft.Owin.Host.SystemWeb&lt;/em&gt;&amp;nbsp; Nuget package in your Asp.net project.&lt;/p&gt; &lt;p&gt;If you implement the the middleware in a separate dll you may simply install the&amp;nbsp; &lt;em&gt;Microsoft.Owin&lt;/em&gt; Nuget package, since you don’t need the &lt;em&gt;Microsoft.Owin.Host.SystemWeb&lt;/em&gt; dll.&lt;/p&gt; &lt;h2&gt;The Problem&lt;/h2&gt; &lt;p&gt;Typically web site supports just a limited set of cultures since each different language requires specific resources that must be produced manually, such as &lt;em&gt;.resx&lt;/em&gt; files and/or whole Views/Pages specific for that language. However, the support of a specific culture based on a supported language typically doesn’t require any specific effort since .Net already contains the numeric formats and date formats for all cultures and one may use a subset of each language that is common to all cultures based on that language.&lt;/p&gt; &lt;p&gt;Thus, for instance, we may use an unique &lt;em&gt;.resx&lt;/em&gt; file for the English language while supporting most of the English based culture(en-US, en-CA, en-GB, en-AU,etc.) if we use a subset of the English language that is common to all cultures. Accordingly, we may set&amp;nbsp; the &lt;a href="http://www.drdobbs.com/windows/culture-and-uiculture/206901403" target="_blank"&gt;UICulture&lt;/a&gt; to &lt;em&gt;en&lt;/em&gt; and the &lt;a href="http://www.drdobbs.com/windows/culture-and-uiculture/206901403" target="_blank"&gt;Culture&lt;/a&gt; to a whole language-country pair.&lt;/p&gt; &lt;p&gt;Any attempt to set a specific culture, must set only of the actually supported cultures, according to a best match algorithm,and when no culture is explicitly set by the user we should extract a culture from the Browser preferences.&lt;/p&gt; &lt;p&gt;Summing up, our specifications are:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;The developer may specify a default culture and a list of supported cultures(all cultures that are supported simultaneously by UI widgets like date pickers, and by the the .resx files included in the project).  &lt;li&gt;The selected culture is assigned to the current thread, and stored in a cookie and/or in the Url(http://mywebsite.com/en-US/...).  &lt;li&gt;A culture may be selected either by creating a globalization cookie and adding it to the response, if culture storing in cookies is enabled, or by issuing to the server a request that contains the chosen culture&amp;nbsp; as the first segment of the Url path(http://mywebsite.com/en-US/...), if culture storing in the Url is enabled.  &lt;li&gt;If no culture is selected the culture is extracted from the browser list of preferred cultures with a best match algorithm, and then it is set as the currently selected culture.  &lt;li&gt;If the culture specified in the path is different from the culture specified in the cookie, the module assumes that the user just clicked a link to change the culture, and uses the culture specified in the path as selected culture.  &lt;li&gt;If there is no perfect match between either a selected culture or the browser cultures the module look for a partial match of just the language part (for instance matching en-CA with en-US, or en). In case of ambiguity the first matching supported language is chosen. If no partial match is found, the module reverts to the default culture. In any case the culture computed this way is set as the currently selected culture  &lt;li&gt;When adding a culture to the list supported cultures one may specify to use only the language part as&lt;a href="http://www.drdobbs.com/windows/culture-and-uiculture/206901403"&gt;&lt;em&gt;UICulture&lt;/em&gt; &lt;/a&gt;(the one used to select the appropriate .resx file). This way, for instance, we may specify both &lt;em&gt;en-US&lt;/em&gt;, and &lt;em&gt;en-CA&lt;/em&gt;, so that dates, numbers and currencies are displayed according to the country, while using an unique &lt;em&gt;en&lt;/em&gt; .resx file for the English language.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;If possible it is advised to select both cookie and and Url path culture storing (that should be the default), because the cookie is useful to remember the selected language in future visits, while including the culture in the path improves SEO and furnishes an easy way to change the selected culture (it is enough to add links with all supported cultures in their path to the page).  &lt;h2&gt;Creating Owin Middleware with Katana&lt;/h2&gt; &lt;p&gt;In Katana the whole Owin function delegates pipeline is specified&amp;nbsp; within the static &lt;em&gt;Configure&lt;/em&gt; method of a &lt;em&gt;Startup&lt;/em&gt; class that is automatically called by the &lt;em&gt;Katana&lt;/em&gt; framework. As a default &lt;em&gt;Katana&lt;/em&gt; looks for a class named &lt;em&gt;Startup&lt;/em&gt; in namespace with the same name of the main assembly. There are &lt;a href="http://www.asp.net/aspnet/overview/owin-and-katana/owin-startup-class-detection" target="_blank"&gt;several ways to change this default&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Thus, we have something like:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d273a283-60e5-433e-93bd-3d73e2bb5db8" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Middleware pipeline&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;partial&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Startup&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Configuration(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;IAppBuilder&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; app)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;app.Use&amp;lt;MyModule&amp;gt;(options);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;app.Use&amp;lt;MyModuleN&amp;gt;(optionsN);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;IAppBuilder&lt;/em&gt; interface contains the &lt;em&gt;IDictionary&lt;/em&gt; used by all function delegates, some dictionary entries exposed as strongly typed properties, and utility methods like the Use&amp;lt;T&amp;gt; method that inserts &lt;em&gt;middleware function delegates&lt;/em&gt; in the pipeline. Each middleware function delegate is implemented by the class passed in the &lt;em&gt;generic&lt;/em&gt; &lt;em&gt;T&lt;/em&gt; of the Use&amp;lt;T&amp;gt;(…) method and it must inherit from the &lt;em&gt;OwinMiddleware&lt;/em&gt; class.&lt;/p&gt; &lt;p&gt;We need&amp;nbsp; to implement just the constructor and the &lt;em&gt;Invoke&lt;/em&gt; method:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:097b3ebc-279f-4772-aa31-a15355fe9260" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Middleware module&lt;/div&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;MyMiddleware&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; : &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinMiddleware&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; LoggerMiddleware(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinMiddleware&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; next, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;MyOptionType myOptions)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;base&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(next)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;_...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;         &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;override&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; async Task Invoke(IOwinContext context)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;await &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Next.Invoke(context);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The constructor is passed the next element in the Owin pipeline, and the same option object we pass to the Use&amp;lt;T&amp;gt;(option) &lt;em&gt;IAppBuilder&lt;/em&gt; method.&lt;/p&gt; &lt;p&gt;In the &lt;em&gt;invoke&lt;/em&gt; method we first do the job of our module and then we call the &lt;em&gt;Invoke&lt;/em&gt; method of the next element in the Owin pipeline.&lt;/p&gt; &lt;p&gt;In order to simplify the Owin pipeline we may group one or several calls to &lt;em&gt;IAppBuilder.Use&amp;lt;T&amp;gt;(object o)&lt;/em&gt; into an &lt;em&gt;IAppBulder&lt;/em&gt; extension method:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:eefdb923-630c-4496-ba03-98fb46c5a281" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;IAppBuilder extension&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;namespace&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; MVCControlsToolkit.Owin.Globalization&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;static&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinGlobalizationHelpers&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="background:#ffffff;color:#000000"&gt;        &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;static&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; UseGlobalization(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;IAppBuilder&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; app,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinGlobalizationOptions&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; options)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;app.Use&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;GlobalizationMidlleware&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;gt;(options);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;After that, in the pipeline definition we may simply call the newly defined extension method instead of &lt;em&gt;IAppBuilder.Use&amp;lt;T&amp;gt;(object o):&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;/em&gt;&amp;nbsp;&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9542d681-221e-4e78-b40e-5b96b342a2f8" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;partial&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Startup&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Configuration(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;IAppBuilder&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; app)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;app.UseGlobalization(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinGlobalizationOptions&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;en-US&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;.Add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;it-IT&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;).Add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;en-US&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;));&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Once the globalization functionality is exposed through the &lt;em&gt;UseGlobalization&lt;/em&gt; extension method the globalization module may be declared internal in our Owin globalization library:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:98fa885d-3816-4989-9a54-bca43547bb4c" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Globalization middleware&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;namespace&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; MVCControlsToolkit.Owin.Globalization.Modules&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;internal&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;GlobalizationMidlleware&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; : &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinMiddleware&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;private&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinGlobalizationOptions&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; options;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;h2&gt;The Globalization Middleware&lt;/h2&gt; &lt;p&gt;In the constructor we just store the &lt;em&gt;options&lt;/em&gt; object:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7a8ddc00-c9b6-4802-988d-469ab73327e0" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;The constructor&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; GlobalizationMidlleware(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinMiddleware&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; next, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinGlobalizationOptions&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; options)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;base&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(next)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (options == &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;throw&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ArgumentNullException&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;options&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.options = options;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;in the &lt;em&gt;Invoke&lt;/em&gt; method: &lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2e431447-822e-41fd-92a5-52fd53bf6db6" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Extracting selected language&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;override&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;async&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Task&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Invoke(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;IOwinContext&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; context)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; urlLanguage = options.CulturePathEnabled ? getPathLanguage(context) : &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; cookieLanguage = options.CulturePathEnabled ? getCookieLanguage(context) : &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; currLanguage = urlLanguage ?? cookieLanguage;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;we extracts the culture from the Url and from the cookie if the associated option is enabled. The &lt;em&gt;Url&lt;/em&gt; culture is preferred (see specifications). The extraction is performed by two private methods&lt;/p&gt; &lt;p&gt;If no culture is selected we revert to the Browser culture, otherwise we select the best match between the selected culture and the supported cultures:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2c3eef5a-f26e-4fe0-a3f4-09843d031576" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Best match&lt;/div&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="6" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; chosenLanguage = currLanguage == &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ?&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;BrowserBestMatch(context) :&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;options.ClosestSupported(currLanguage);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;OwinSupportedCulture&lt;/em&gt; class represents the matched supported culture:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c0333d1f-200b-4856-994f-e0f8b5fc97e4" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;internal&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Name { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; UIName { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; MatchLevel { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Where MatchLevel is an integer that encodes the kind of match that took place with the supported culture (perfect match, language part only, no match the default culture was selected)&lt;/p&gt; &lt;p&gt;Then we may set the chosen cultures in the current thread:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e931dfb6-49be-4a0b-9a37-aa1b6db283ab" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Setting cultures&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol start="9" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Thread&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.CurrentThread.CurrentUICulture = &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;CultureInfo&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(chosenLanguage.UIName);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Thread&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.CurrentThread.CurrentCulture = &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;CultureInfo&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(chosenLanguage.Name);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now we must store the selected culture in the cookie, and/or Url if it is not already stored there.&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2c5672ee-1b68-44fb-981f-5b5382aa83ff" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Setting the culture in the Url&lt;/div&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="13" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (options.CulturePathEnabled &amp;amp;&amp;amp; &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;options.AlwaysRedirectOnCulturePath &amp;amp;&amp;amp; &lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;chosenLanguage.Name != urlLanguage)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Path = context.Request.Path;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; fPath = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!Path.HasValue) fPath = chosenLanguage.Name;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (urlLanguage == &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;fPath = chosenLanguage.Name +&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;(Path.Value[0] == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;/&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ? Path.Value :&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; + Path.Value&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; position = Path.Value.Substring(1).IndexOf(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;/&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (position &amp;lt; 0) fPath = chosenLanguage.Name;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; fPath = chosenLanguage.Name + Path.Value.Substring(position + 1);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; builder = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;UriBuilder&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(context.Request.Uri);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;builder.Path = fPath;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;context.Response.Redirect(builder.Uri.AbsoluteUri);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;If the&amp;nbsp; the culture in the path is handled,&amp;nbsp; if automatic redirect to an Url with a culture in the path is enabled (the default), and if the selected culture is not already contained in the path, then an Url&amp;nbsp; containing the newly selected culture is computed (any previous culture possibly contained in the Url is removed). After that the execution of the Owin pipeline is aborted and a redirect to the newly computed Url is performed by calling the &lt;em&gt;Response.Redirect method&lt;/em&gt; of the &lt;em&gt;context&lt;/em&gt; object passed as argument to the &lt;em&gt;Invoke&lt;/em&gt; method.&lt;/p&gt; &lt;p&gt;If instead culture storing is enabled and cookie doesn’t contain already the newly selected culture, a new cookie is added to the response:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:78c634d6-4b76-4fd7-ad58-218c4335839a" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Cookie preparation&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol start="40" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (options.CookieEnabled &amp;amp;&amp;amp; &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;cookieLanguage != chosenLanguage.Name)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;context.Response.Cookies&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.Append(options.CookieName, chosenLanguage.Name);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;Finally we call the next element of the Owin pipeline:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:61653355-234b-4587-a650-78825f1286a7" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol start="46" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;await&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Next.Invoke(context);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;OwinGlobalizationOptions.ClosestSupported&lt;/em&gt; method that performs the best match between the culture the user is trying to set and any of the supported culture is quite simple:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ec665f33-2282-45c1-8e61-ee52c12778b2" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Best match&lt;/div&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;internal&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ClosestSupported(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; culture)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!ValidateCulture(culture, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; { &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;Name = defaultCulture, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;UIName = defaultCulture, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;MatchLevel = 0 };&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;culture = culture.ToLowerInvariant();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinGlobalizationCulture&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; res;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (supportedCultures.TryGetValue(culture, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;out&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; res))&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;Name = res.Name,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;UIName = res.GetUiCulture(),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;MatchLevel = 2&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (culture.Length &amp;gt; 2)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;culture = culture.Substring(0, 2);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (supportedCultures.TryGetValue(culture, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;out&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; res))&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;Name = res.Name,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;UIName = res.GetUiCulture(),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;MatchLevel = 1&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; { &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;Name = defaultCulture, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;UIName = defaultCulture, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;MatchLevel = 0 };&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;If the culture string is invalid, the default culture is returned.&lt;/p&gt; &lt;p&gt;Otherwise the method looks in the dictionary of all supported cultures. If no match is found a match with just the language part is tried, and in case of failure the default culture is returned. The &lt;em&gt;GetUICulture&lt;/em&gt; method is defined below:&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9b06b8ce-0e85-4696-906c-b9b227738bee" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Supported culture class&lt;/div&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinGlobalizationCulture&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Name { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;bool&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; UIIsNeutral { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; GetUiCulture()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (UIIsNeutral &amp;amp;&amp;amp; Name.Length &amp;gt; 2) &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Name.Substring(0, 2);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Name;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The best match with the cultures supported by the browser is a little bit more complex since the browser may support several cultures and may give a preference (0 to 1 float) to each of them (&lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html" target="_blank"&gt;Accept-Language header&lt;/a&gt;):&lt;/p&gt; &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b16b6587-dff6-4533-bfd5-af443d8819eb" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Browser best match&lt;/div&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;private&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; BrowserBestMatch(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;IOwinContext&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; context)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;[] acceptLanguageHeader = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (context.Request.Headers&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;.TryGetValue(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Accept-Language&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;out&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; acceptLanguageHeader) &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&amp;amp;&amp;amp; acceptLanguageHeader != &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;float&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; maxVote = -1.0f;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; maxElement = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;foreach&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; language &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; parseLanguages(acceptLanguageHeader))&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; currLanguage = &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;options.ClosestSupported(language.Name);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (currLanguage == &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;continue&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;float&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; currVote = currLanguage.MatchLevel * 10 &lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;+ language.Q;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (currVote &amp;gt; maxVote)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;maxVote = currVote;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;maxElement = currLanguage;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; maxElement ?? &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;Name = options.DefaultCulture,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;UIName = options.DefaultCulture,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;MatchLevel = 0&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OwinSupportedCulture&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;Name = options.DefaultCulture,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;UIName = options.DefaultCulture,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;MatchLevel = 0&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The “Accept-Language” entry in the &lt;em&gt;context.Request.Headers&lt;/em&gt; dictionary contains an array with all preferred cultures. The &lt;em&gt;parseLanguages&lt;/em&gt; private method parse&amp;nbsp; each culture entry to extract the current name and the &lt;em&gt;Q&lt;/em&gt; 0-1 float representing the preference. A loop is performed to compute the the culture with the maximum vote, where the vote takes into account the match level with the closest supported culture and the &lt;em&gt;Q&lt;/em&gt; of each browser culture. &lt;/p&gt; &lt;p&gt;The whole sources are available on &lt;a href="https://owinglobalization.codeplex.com/SourceControl/latest" target="_blank"&gt;Codeplex&lt;/a&gt;.&lt;/p&gt; &lt;h2&gt;How to use the Owin Globalization Module&lt;/h2&gt; &lt;p&gt;Install the &lt;em&gt;MVCControlsToolkit.Owin.Globalization&lt;/em&gt; Nuget package in your Mvc 5 project, then open the &lt;em&gt;Startup.cs &lt;/em&gt;file located in the Web Site root, and add the Owin Globalization module as follows:  &lt;p&gt;&lt;img alt="Globalization helper" src="http://www.mvc-controls.com/Media/Default/Page/OwinModuleCall.PNG" width="524" height="172"&gt;  &lt;p&gt;If culture storing in the Url is enabled you need also to add the {language}/ segment to all routing rules. Thus for instance:  &lt;p&gt;&lt;img alt="Standard routing rule" src="http://www.mvc-controls.com/Media/Default/Page/StandardRouting.PNG" width="435" height="109"&gt;  &lt;p&gt;becomes:  &lt;p&gt;&lt;img alt="Culture enhanced routing rule" src="http://www.mvc-controls.com/Media/Default/Page/CultureEnhancedRoutingRule.PNG" width="416" height="119"&gt;  &lt;h4&gt;Owin Globalization Options&lt;/h4&gt; &lt;p&gt;The &lt;em&gt;UseGlobalization&lt;/em&gt; extension accepts an &lt;em&gt;OwinGlobalizatioOptions&lt;/em&gt; object containing all globalization options as its sole argument. In turn, the &lt;em&gt;OwinGlobalizatioOptions&lt;/em&gt;&amp;nbsp; constructor accepts the default culture as its first obligatory argument, and a second optional boolean that specifies if the UI culture must use only the language part of the default culture. Further options may be added with a fluent interface:  &lt;p&gt;&lt;em&gt;.Add(string culture, bool uIIsNeutral = false)&lt;/em&gt;  &lt;p&gt;Adds a new supported culture. If &lt;em&gt;uIIsNeutral &lt;/em&gt;is &lt;em&gt;true&lt;/em&gt; only the language part of the provided culture is used to set the &lt;a href="http://www.drdobbs.com/windows/culture-and-uiculture/206901403"&gt;UICulture&lt;/a&gt;.  &lt;p&gt;As a default the selected culture is stored both in the first segment of the Url path and in a cookie whose name is "preferred_culture". The methods below change these default options:  &lt;p&gt;&lt;em&gt;.DisableCultureInPath()&lt;/em&gt;  &lt;p&gt;Disables storing the selected culture in the Url.  &lt;p&gt;&lt;em&gt;.DisableRedirect()&lt;/em&gt;  &lt;p&gt;If culture storing in the Url is enabled it disables the automatic redirect to an Url containing the selected culture as first segment of the path when an Url containing no culture in the path is received.  &lt;p&gt;&lt;em&gt;.DisableCookie()&lt;/em&gt;  &lt;p&gt;Disables storing the selected culture in a cookie  &lt;p&gt;&lt;em&gt;.CustomCookieName(string name)&lt;/em&gt;  &lt;p&gt;If storing the selected culture in a cookie is enabled it changes the globalization cookie default name.&lt;/p&gt;</description><pubDate>Sun, 23 Feb 2014 12:42:01 GMT</pubDate><guid isPermaLink="true">http://datamoving.mvc-controls.com:80/blog/implementing-an-owin-globalization-module-with-katana</guid></item><item><title>Data Moving SPA with a Context-Dependent Menu</title><link>http://datamoving.mvc-controls.com:80/blog/data-moving-spa-with-a-context-dependent-menu</link><description>&lt;p&gt;The &lt;a title="http://www.mvc-controls.com/controls/menu" href="http://www.mvc-controls.com/controls/menu"&gt;Data Moving&amp;nbsp; Menu Control&lt;/a&gt; may be used to navigate among the virtual pages of a Single Page Application, too. In this step by step tutorial I will show you how to configure the menu control, and how to adapt it to the authorizations of the currently logged user .&lt;/p&gt; &lt;p&gt;The full working code is available in the “ContextDependentMenu” file &lt;a href="http://www.mvc-controls.com/free_software/examples" target="_blank"&gt;on this site&lt;/a&gt; and on the &lt;a href="https://datamovingexamples.codeplex.com/releases" target="_blank"&gt;Data Moving Plugin Examples Codeplex site download&amp;nbsp; area.&lt;/a&gt; The Visual studio solution must be activated by installing the&amp;nbsp; DataMovingPlugin5Examples.x.x.x.nupkg file you get with the product.&lt;/p&gt; &lt;p&gt;The result that you’ll obtain is shown in this Video:&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;iframe height="480" src="//www.youtube.com/embed/OynE3aMbapw?rel=0&amp;amp;vq=hd720&amp;amp;autoplay=1" frameborder="0" width="640" allowfullscreen=""&gt;&lt;/iframe&gt;&lt;/p&gt; &lt;p&gt;As a first step let select the SPA Mvc 5/WebApi 2 SPA project template in visual studio. All SPA visual studio templates may be downloaded from the&amp;nbsp; &lt;a href="https://datamovingexamples.codeplex.com/" target="_blank"&gt;Data Moving Examples Codeplex Site&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&lt;u&gt;Select File-&amp;gt;New-&amp;gt;Project&lt;/u&gt; in VS 2013:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/ProjectSelection.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ProjectSelection" border="0" alt="ProjectSelection" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/ProjectSelection_thumb.png" width="554" height="274"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Then name the new project:, SPAMenuTutorial:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/ProjectName.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ProjectName" border="0" alt="ProjectName" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/ProjectName_thumb.png" width="558" height="99"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The result should be this one:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/FullProject.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="FullProject" border="0" alt="FullProject" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/FullProject_thumb.png" width="392" height="572"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Now you need to install the Data Moving Plug-in for Mvc 5. Right click on the “References” and select: “Manage Nuget Packages…”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/SelectLocalFeed.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SelectLocalFeed" border="0" alt="SelectLocalFeed" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/SelectLocalFeed_thumb.png" width="314" height="279"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In the window that appears, select the local Nuget source on your hard disk where you copied all Data Moving Plug-in Nuget packages:&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/DMPMVC5.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="DMPMVC5" border="0" alt="DMPMVC5" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/DMPMVC5_thumb.png" width="522" height="523"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Now select the “Data Moving Plug-in 5”, and install it.&lt;/p&gt; &lt;p&gt;Before running the initial SPA that the visual studio template created for you, your Product Key must be placed in the application root Web.Config, in the AppSettings section:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:59866d91-3f53-424a-9bd5-bc2f70d61269" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;appSettings&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;add&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;webpages:Version&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;3.0.0.0&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; /&amp;gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;add&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;webpages:Enabled&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; /&amp;gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;add&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;ClientValidationEnabled&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; /&amp;gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;add&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;UnobtrusiveJavaScriptEnabled&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; /&amp;gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;add&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;DMPDefaultStyle&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;Bootstrap&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; /&amp;gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;add&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;DMPProductKey&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;P-ZzKk-****...........&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt; /&amp;gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;appSettings&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now you may run the project:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/CourtesyPage.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CourtesyPage" border="0" alt="CourtesyPage" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/CourtesyPage_thumb.png" width="556" height="427"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;An essential SPA with just an home page, and Login, Logout, and Unauthorized page is created.&lt;/p&gt; &lt;p&gt;All&amp;nbsp; these&amp;nbsp; SpaViews are placed in the “Basic” SPA Module that is loaded as soon as the application starts:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/InitialViews.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="InitialViews" border="0" alt="InitialViews" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/InitialViews_thumb.png" width="427" height="413"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The Application folder contains just two dynamic JavaScript files: &lt;/p&gt; &lt;ol&gt; &lt;li&gt;Application/MainJs. It contains the SPA start-up code and the definition of the application ViewModel.  &lt;li&gt;Application/AuthorizationJs. This JavaScript file is called by the previous Application/MainJs file and contains all authorization rules for the application SPAViews. Initially the rule set is empty, and the file contains just a commented-out example that shows how to define a rule:&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5e23b222-133e-43be-8e51-dc6fdafc6ea1" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;using&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; MVCControlsToolkit.Controls&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;script&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; () {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//Add here authorization rules for each virtual page&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//(rules may include also the page role)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//as the one commented out below&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;@(SPAAuthorizations.New().Claims("logged")&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;.Roles("&amp;lt;role1&amp;gt;", "&amp;lt;role2&amp;gt;")&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;.AddTo("&amp;lt;module name&amp;gt;", "&amp;lt;view name&amp;gt;", &lt;/span&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;"&amp;lt;role name (optional)&amp;gt;"))&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;})();&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;script&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;All SPA templates use bootstrap for styling, and install a bootstrap Nuget package that provides just the “core” CSS without any specific theme. In order to improve, the appearance of our demo we may download the default bootstrap theme from the &lt;a href="http://getbootstrap.com/" target="_blank"&gt;bootstrap web site&lt;/a&gt;:&amp;nbsp; “bootstrap-theme.min.css “and “bootstrap-theme.css”. Just add these two files to the web site “Content” folder, and then add&amp;nbsp; "~/Content/bootstrap-theme.css", to the "~/Content/css" style bundle definition in the App_Start/BundleConfig.cs file that contains all bundle definitions:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2ea32e10-a10f-43b8-b916-e20a15ad1f0a" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;bundles.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; StyleBundle(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"~/Content/css"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;).Include(&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"~/Content/bootstrap.css"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"~/Content/bootstrap-theme.css"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;// &amp;lt;-Add new file reference here&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"~/Content/MVCControlToolkit.ControlsExt.Mobi-"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; + version + &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;".min.css"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"~/Content/Site.css"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;));&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Without the addition of a theme the appearance of the menu we are going to build would be quite “bad”.&lt;/p&gt; &lt;p&gt;Our plan is:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Defining some users and roles in the application security Database  &lt;li&gt;Defining a new SPA Module with 5 simple SPAViews  &lt;li&gt;Declaring 3 authorization rules that allow just users with the “admins” role to access&amp;nbsp; SPAView 3, 4&amp;nbsp; and 5  &lt;li&gt;Defining a Menu to navigate our SPAViews  &lt;li&gt;Adapting the Menu to the current page and to the current logged user.&lt;/li&gt;&lt;/ol&gt; &lt;h2&gt;Defining the security Database&lt;/h2&gt; &lt;p&gt;The Models/ApplicationDbContext.cs file contains a Database seeding function that defines the “admins” role and two users: an administrator and a normal user. In an actual application we should modify this code to adapt it to our needs. In this simple tutorial we may use the default users and roles.&lt;/p&gt; &lt;p&gt;The seeding function is&amp;nbsp; “activated “ by a few lines of code in the &lt;em&gt;Global.asax&lt;/em&gt; that are initially commented-out:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e943d04e-ebc7-45f3-b30a-ff2e50d476a2" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;protected&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;void&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; Application_Start()&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;{&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;....&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;....&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;....&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//Uncomment to prepopulate db with sample users&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//See ApplicationDbContext.cs&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #008000"&gt;/*&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #008000"&gt;Database.SetInitializer&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #008000"&gt;&amp;lt;SPAMenuTutorial.Models.ApplicationDbContext&amp;gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #008000"&gt;(new SPAMenuTutorial.Models.ApplicationDbContextInitializer());&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #008000"&gt;*/&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Let uncomment them, and run the application. Now we may login as “admins” with the credentials:&lt;/p&gt; &lt;p&gt;username: admin, password: padmin, as shown in the previous video.&lt;/p&gt; &lt;h2&gt;Defining a new SPA Module with 5 simple SPAViews &lt;/h2&gt; &lt;p&gt;Now, in visual studio, right click on the Views/Templates folder and select “new folder”. Name the new folder:&amp;nbsp; “MenuExample”.This folder will contain all files of the new &lt;em&gt;MenuExample&lt;/em&gt; SPA Module that we are going to define. &lt;/p&gt; &lt;p&gt;Now, in visual studio right click on the “MenuExample” folder and select: “New Item”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/SPAModule.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SPAModule" border="0" alt="SPAModule" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/SPAModule_thumb.png" width="451" height="498"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Select “SPAModule”, and then give to the new SPA module the same name of the previous folder: “MenuExample”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/ModuleName.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ModuleName" border="0" alt="ModuleName" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/ModuleName_thumb.png" width="264" height="104"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;We should get the following files structure:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/ModuleStructure.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ModuleStructure" border="0" alt="ModuleStructure" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/ModuleStructure_thumb.png" width="459" height="228"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The two &lt;em&gt;Main&lt;/em&gt; and &lt;em&gt;MainJs&lt;/em&gt; files contain the logic to assemble all SPAViews we are going to define into an unique SPAModule. More specifically, &lt;em&gt;Main.cshtml&lt;/em&gt; contains the logic to assemble all templates, and to route any incoming View request to the right SPAView template, while &lt;em&gt;MainJS.cshtml&lt;/em&gt; contains the logic to assemble the AMD code associated to all SPAViews into the unique JavaScript file associated to the whole “MenuExample” module, and the logic to route any SPAView request to the right chunck of JavaScript code&amp;nbsp; that was previously aggregated to the “MenuExample” module.&lt;/p&gt; &lt;p&gt;Since ,as in most of the cases, we don’t need to modify the default routing rules you don’t need to modify &lt;em&gt;Main&lt;/em&gt;, and &lt;em&gt;MainJs&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;Now we need to define the Action method that will deploy the “MenuExample” module to the client. Go to the “Controllers/TemplatesController.cs” file,&amp;nbsp; copy the example “MyTemplate” action method…&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/ActionMethod.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ActionMethod" border="0" alt="ActionMethod" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/ActionMethod_thumb.png" width="554" height="153"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;…paste it, and rename any occurrence of “MyModule” into “MenuExample”:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4b85b3c7-b9c8-4128-a709-4889eadb1f29" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;ActionResult&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; MenuExample(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;bool&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; isJs)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;{&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; module = &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"MenuExample/Main"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (isJs) &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;this&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.MinifiedJavascriptResult(module + &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Js"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; PartialView(module);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now we may define all SPAViews. &lt;/p&gt; &lt;p&gt;Right click on the “MenuExample” folder, and select again “New Item”. However this time, choose “SPAView”. Repeat the same operation five times, and give to the SPAViews the names:&lt;/p&gt; &lt;p&gt;“Page1”, “Page2”, “Page3”, “Page4”, and “Page5”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/AllPages.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="AllPages" border="0" alt="AllPages" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/AllPages_thumb.png" width="480" height="373"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Now open each Page1.cshtml…Page5.cshtml file:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f758c8a5-4360-4e9c-b42c-05ef6657aaa8" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt;@model MyViewModel&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;div&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;="&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;Html.PrefixedId(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"pageRoot"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;data-helper-prefix&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;="&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;Html.PrefixedId(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;""&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;"&amp;gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;h3&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt;View title if any&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;h3&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;div&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Then add the “main-page” Css class&amp;nbsp; and a different header to each page:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9af4b811-d358-428d-bde5-681d41b3b834" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt;@model MyViewModel&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;div&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;="main-page"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;="&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;Html.PrefixedId(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"pageRoot"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;data-helper-prefix&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;="&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;Html.PrefixedId(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;""&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;"&amp;gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;h3&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;Page 1&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;h3&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;div&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;You don’t need to define a page ViewModel, since we will use all these pages just to test our menu.&lt;/p&gt; &lt;p&gt;Since pages have no ViewModel wee need to comment-out the instruction that prepare the SPAView JavaScript model in each PagexJs.cshtml file. In each PagexJs.cshtml file locate the instruction:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:eabe6cfc-973e-4651-978b-ae15599a91f8" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;vm.Content = ko.mapping.fromJS(viewModelContent);&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;and comment it out:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:233389ab-0fee-41f5-9154-c612949aa8dd" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;mvcct.core.moduleResult(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (vm) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (!vm._initialized) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;vm._initialized = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//vm.Content = ko.mapping.fromJS(viewModelContent);&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Done! Now you may navigate to each of the newly created SPAViews, by adding &lt;em&gt;view&lt;/em&gt; and &lt;em&gt;module&lt;/em&gt; parameters to the root application&lt;em&gt; url&lt;/em&gt; that Visual Studio automatically set in you browser:&lt;/p&gt; &lt;p&gt;http://localhost:3291/?module=MenuExample&amp;amp;view=Page1&lt;/p&gt; &lt;h2&gt;Declaring the authorization rules&lt;/h2&gt; &lt;p&gt;As already announced pages 3, 4, 5 must be available only for users with the role &lt;em&gt;admins&lt;/em&gt;. Open the Views/Templates/Application/AuthorizationJs.cshtml file and add the three rules below:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:87dda6b1-dc7b-4257-a575-626d904be333" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 500px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;using&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; MVCControlsToolkit.Controls&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;script&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; () {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//Add here authorization rules for each virtual page&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//(rules may include also the page role)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//as the one commented out below&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;@(SPAAuthorizations.New().Claims("logged")&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;.Roles("&amp;lt;role1&amp;gt;", "&amp;lt;role2&amp;gt;")&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;.AddTo("&amp;lt;module name&amp;gt;", "&amp;lt;view name&amp;gt;", &lt;/span&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;"&amp;lt;role name (optional)&amp;gt;"))&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SPAAuthorizations&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.New().Claims(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"logged"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Roles(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"admins"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.AddTo(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"MenuExample"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Page3"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SPAAuthorizations&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.New().Claims(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"logged"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Roles(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"admins"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.AddTo(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"MenuExample"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Page4"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SPAAuthorizations&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.New().Claims(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"logged"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Roles(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"admins"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.AddTo(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"MenuExample"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Page5"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;})();&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;script&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;In this simple example we specified access rules for each single SPAView, but in more complex applications you may write also something like: &lt;em&gt;AddTo(“MenuExample”,&amp;nbsp; “*”)&lt;/em&gt;, in which case the requirements apply to all SpaViews of the “MenuExample” module. Then, exceptions to this general rule may be applied to specific SPAViews.&lt;/p&gt; &lt;p&gt;Now when&amp;nbsp; you navigate, to Page3-5, the login form appears. Test it with Page4:&lt;/p&gt; &lt;p&gt;http://localhost:3291/?module=MenuExample&amp;amp;view=Page4&lt;/p&gt; &lt;p&gt;After you successfully login, Page4 appears. &lt;/p&gt; &lt;p&gt;Now,&amp;nbsp; try to login with username: normalUser. and password: pnormalUser;&amp;nbsp; you will see the following complaint page:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/Unauthorized.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Unauthorized" border="0" alt="Unauthorized" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/Unauthorized_thumb.png" width="529" height="194"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Wow! We need only a “smart menu” to navigate our application.&lt;/p&gt; &lt;h2&gt;Making Room for our Menu &lt;/h2&gt; &lt;p&gt;All SPAViews are loaded in the Views/Home/Index.cshtml page. The code in the above page do the following:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6a025792-eb6c-4334-bde9-8695762f7155" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@{&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; h = Html.SendToClient(m =&amp;gt; m, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"applicationModel"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;""&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;);}&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Declares the application ViewModel, and get a client ViewModel aware HtmlHelper&amp;lt;ApplicationModel&amp;gt;, that is then used to declare the SPAViews hosts where all the SPAViews may be loaded:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:323a3d53-fcaf-4108-9859-4bfbed92d1db" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px" start="2"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;div&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;="content"&amp;gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;h.ClientTreeIteratorFor(m =&amp;gt; m.MainContent, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;null&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"mainAfterRender"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"mainBeforeRemove"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;wrapper: &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;ExternalContainerType&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.div,&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;wrapperAttributes: &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new{&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;id = &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"main_host"}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;div&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Each SPAView host is bound to an applicationModel Property. The initial application ViewModel contains just a single property, called &lt;em&gt;MainContent&lt;/em&gt;, used by the main content SPAView host, shown above.&amp;nbsp; &lt;em&gt;mainAfterRender&lt;/em&gt; and &lt;em&gt;mainbeforeRemove&lt;/em&gt; are applicationModel methods defined in Views/Templates/Application.MainJs.cshtml, that provide respectively content fade-in and content fade-out.&lt;/p&gt; &lt;p&gt;Since we need a further SPAView host for our menu we must add a new property to the application ViewModel:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:92a82323-656d-4da7-acbf-3fb8e98f1e48" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;class&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;ApplicationModel&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;{&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//main virtual page host&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;baseViewModel&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SampleClass&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;&amp;gt; MainContent { &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;get&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;set&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; }&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//add here further virtual page hosts&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//Main Menu Host&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;baseViewModel&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SampleClass&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;&amp;gt; MenuContent { &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;get&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;set&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; }&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//initial page to load&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;externalSPALink&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; InitialPage { &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;get&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;set&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; }&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now we may define our Main Menu host. We place it on top of the Main Content:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:78ed060b-86e9-4e8a-98fe-73a62760a6ea" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;div&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;="content"&amp;gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;h.ClientTreeIteratorFor(m =&amp;gt; m.MenuContent, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;null&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;wrapper: &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;ExternalContainerType&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.nav,&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;wrapperAttributes: &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; { id = &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"menu_host"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; }&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;h.ClientTreeIteratorFor(m =&amp;gt; m.MainContent, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;null&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"mainAfterRender"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"mainBeforeRemove"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;wrapper: &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;ExternalContainerType&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.div,&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;wrapperAttributes: &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new{&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;id = &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"main_host"}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;div&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;We enclose the our main menu in a &lt;em&gt;nav&lt;/em&gt; tag to improve the application accessibility. The Main Menu host doesn’t need fade-in, and fade-out capability, since it will never be removed, but only modified to adapt it to the context.&lt;/p&gt; &lt;p&gt;We need some Css to align the menu with the main content. Open the Content/Site.css file and append:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:13e8eba7-8794-4c96-96a8-8fb6a47f93e5" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #006400"&gt;/*Menu*/&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #800000"&gt;#menu_host{&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;width&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;:&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;800px&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;margin&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;: &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;10px&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;auto&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;10px&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;auto&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;min-height&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;: &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;50px&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;border&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;: &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;none&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h2&gt;Defining a Menu to Navigate our SPAViews &lt;/h2&gt; &lt;p&gt;We will add the “Menu” SpaView to Basic module that is loaded as soon as the application starts Right click on the Views/Templates/Basic folder and add a new SPAView called: “Menu”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/MenuAdded.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MenuAdded" border="0" alt="MenuAdded" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/MenuAdded_thumb.png" width="482" height="426"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The Data Moving control suite urnish the default &lt;em&gt;SimpleMenuItem&lt;/em&gt; class to be used as ViewModel for each menu item. We may decide to use it, inherit from it or to use a custom class. The definition of the &lt;em&gt;SimpleMenuItemClass&lt;/em&gt; is:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fdc7b53a-ee7a-43f5-b454-6e206c951985" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;class&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SimpleMenuItem&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;{&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; Text { &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;get&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;set&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; }&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; Link { &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;get&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;set&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; }&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; UniqueName { &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;get&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;set&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; }&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; Target { &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;get&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;set&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; }&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;List&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SimpleMenuItem&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;&amp;gt; Children { &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;get&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;set&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; }&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;When the Menu works in a “standard” Mvc application the &lt;em&gt;Link&lt;/em&gt; property contains either an Url or the name of a JavaScript function, preceeded either by @, or #&amp;nbsp; to be executed when the menu item is clicked. Analogously the &lt;em&gt;Target&lt;/em&gt; property contains the target where to open the Url.&lt;/p&gt; &lt;p&gt;In the case of a SPA we must supply a function that provides a custom interpretation of both &lt;em&gt;Link&lt;/em&gt; and &lt;em&gt;Target&lt;/em&gt;. In the simplest case a SPAView may be referenced with a string of the type &amp;lt;module name&amp;gt;.&amp;lt;view name&amp;gt; in the Link, while the &lt;em&gt;host&lt;/em&gt; where to load the SPAView may be denotated by its index into an array of possible &lt;em&gt;hosts&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;Thus, for Instance, “MenuExample.Page4” denotes the SPAView&amp;nbsp; “Page4” contained in the “MenuExample” module. If needed, the notation may be extended to include also possible roles of the SPAView, and also an input object to pass to the SPAView:&lt;/p&gt; &lt;p&gt;&amp;lt;module&amp;gt;.&amp;lt;view&amp;gt;.&amp;lt;optional role&amp;gt;#&amp;lt;optional json representation of the SPAView input&amp;gt;&lt;/p&gt; &lt;p&gt;In our simple example the custom Link+Target processing function will accept just the simple notation &amp;lt;module&amp;gt;.&amp;lt;view&amp;gt; plus standard Urls:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b9f926a4-916b-4830-81b2-067f7e1e869b" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;vm.Content.virtualNavigation = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (action, target) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (!action) &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (action.indexOf(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"/"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;) == 0 ||&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;action.indexOf(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"http"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;) == 0 ) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (target) window.open(action, target);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;else&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; window.location.href = action;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; parts = action.split(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"."&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; host = target ? parseInt(target) : 0;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;vm._interfaces.mainHosts[host](&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;mvcct.ko.dynamicTemplates.defaultPageStore.get(&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; mvcct.ko.dynamicTemplates.virtualReference(&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;parts[0], parts[1])));&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;};&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Standard Urls are processed first, otherwise we retrieve the SPAView specified in the &lt;em&gt;action&lt;/em&gt; parameter from the default page store. The host&amp;nbsp; where to place the SPAView is decided by interpreting the &lt;em&gt;target&lt;/em&gt; argument as an index in the array of all application root hosts that is inserted in the &lt;em&gt;_interfaces&lt;/em&gt; property of the Menu ViewModel.&lt;/p&gt; &lt;p&gt;The &lt;em&gt;_interfaces&lt;/em&gt; property is copied in each SPAView from the &lt;em&gt;interfaces&lt;/em&gt; property of the application ViewModel by&amp;nbsp; default &lt;a href="http://www.mvc-controls.com/blog/data-moving-plug-in-spa-view-engine-handling-contextual-information-and-user-authorization" target="_blank"&gt;context rules&lt;/a&gt; that are run each time a SPAView is loaded.&amp;nbsp; All context rules are defined in the file: Script/Modules/contextRules.js. Below the default context rule that provide to each SPAView all interfaces needed to interact with the application:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:dc61e5d4-160a-485f-91a1-bc353fcc545a" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;mvcct.ko.dynamicTemplates.addContextRule(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (data, cb) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (mvcct.ko.dynamicTemplates.isBaseViewModel(data)) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;data._interfaces = applicationModel.interfaces;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;});&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;interfaces&lt;/em&gt; property of the application ViewModel is defined in the Views/Templates/Application.MainJs.cshtml file. Below the default definition:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b5053a5a-db30-47de-8142-6dee276e609d" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt; Put here all instances of the interface implementations &lt;/span&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;you need in the application &lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt; They will be added to all ViewModel by the context rules&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces = {};&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces.uiBlock = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; uiBlockInterface();&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;As a default the &lt;em&gt;interfaces&lt;/em&gt; property contains just an implementation of the interface used to “block” the content of a DOM during a communication with the server. We must add also the array of all &lt;em&gt;hosts&lt;/em&gt; (in our case there are just 2&amp;nbsp; &lt;em&gt;hosts&lt;/em&gt;):&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d17876a0-09fd-4429-bd38-b8df5fc2ccd5" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt; Put here all instances of the interface implementations &lt;/span&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;you need in the application &lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt; They will be added to all ViewModel by the context rules&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces = {};&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces.uiBlock = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; uiBlockInterface();&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces.mainHosts =&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;[applicationModel.MainContent, applicationModel.MenuContent];&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;In the same Views/Templates/Application.MainJs.cshtml file we must modify the code that loads the initial SPAViews:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:141243d7-6e64-411e-b9d0-d3f4a144ec46" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.MainContent(&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;mvcct.ko.dynamicTemplates.defaultPageStore.get(initLink ||&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; mvcct.ko.dynamicTemplates.virtualReference(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Basic"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Home"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)));&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;…because we must load also our menu:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9d2011b8-d737-4434-92ff-469b5a0fb33d" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.MenuContent(&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; mvcct.ko.dynamicTemplates.baseViewModel(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Basic"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Menu"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;));&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.MainContent(&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;mvcct.ko.dynamicTemplates.defaultPageStore.get(initLink ||&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; mvcct.ko.dynamicTemplates.virtualReference(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Basic"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Home"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)));&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The Menu SPAView is not handled by any page store, since it will never be removed from its host.&lt;/p&gt; &lt;p&gt;The &lt;em&gt;vm.Content.virtualNavigation&lt;/em&gt; method definition may be placed immediately after the ViewModel initialization in the MenuJS.cshtml file:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:dc841803-d6cf-42b3-b72a-0f99f416f3b6" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;mvcct.core.moduleResult(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (vm) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (!vm._initialized) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;vm._initialized = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;vm.Content = ko.mapping.fromJS(viewModelContent);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt; Initialization code executed only after View &lt;/span&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;creation or View redirect&amp;nbsp; &lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;vm.Content.virtualNavigation = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (action, target) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;...&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;...&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now we must define &lt;em&gt;viewModelContent&lt;/em&gt; to bethe object hierachy that contains all Menu information. &lt;/p&gt; &lt;p&gt;Usually, the ViewModel content is initialized by serializing in JavaScript a .Net data structure, at the beginning of any …Js file:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e5edc5ad-57d5-4234-9044-a120d791eb59" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #006400"&gt;@Html.JavaScriptDefine("viewModelContent", &lt;/span&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;new &amp;lt;dotnet viewModel here&amp;gt;())&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;In our case the .Net data structure is a hierarchy of &lt;em&gt;SimpleMenuItem&lt;/em&gt; objects that we may build easily with the helper &lt;em&gt;SimpleMenuBuilder&lt;/em&gt; class: &lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:183da99b-64e1-4f18-a523-61465befd855" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;script&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;&amp;gt;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@{&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; menuItems = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SimpleMenuBuilder&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;()&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Home"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Basic.Home"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Page 1"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"MenuExample.Page1"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Page 2"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"MenuExample.Page2"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"private area"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Down()&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Page 3"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"MenuExample.Page3"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Page 4"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"MenuExample.Page4"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Page 5"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"MenuExample.Page5"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Up()&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"External Links"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Down()&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Data Moving Controls"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"http://www.mvc-controls.com"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Add(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"knockout.js"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"http://knockoutjs.com/"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;null&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;, &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"_blank"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Down()&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Get();&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; () {&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;Html.JavaScriptDefine(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"viewModelContent"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SimpleMenuItem&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; {Children=menuItems })&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;...&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;...&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;We added also two sub-items that navigate to external pages.&lt;/p&gt; &lt;p&gt;Now it’s finally time to use the Data Moving Menu control. Open the &lt;em&gt;Menu.cshtml&lt;/em&gt; file, and substitute its content with:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:157026db-8971-444a-8ae2-127f8896b0c7" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@model &lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;MVCControlsToolkit.Controls.&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SimpleMenuItem&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@{&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; builder = Html.ExtendedClientMenuFor(&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;m =&amp;gt; m.Children, m =&amp;gt; m.Link,&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; { @class = &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"mainmenu"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; });&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;HttpContext&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.Current.Request.Browser.IsMobileDevice)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;{&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;builder = builder.ActiveOnlyOnClick();&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;builder.Target(m =&amp;gt; m.Target)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.Radiuses(0.5f, 1f, 0.5f)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.TemplatesBaseName(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Basic_MenuItem"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.TemplateSelector(&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;@"function(x){&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #a31515"&gt;return (x.Children.peek() ?&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #a31515"&gt;'Basic_MenuItem1' : 'Basic_MenuItem0');&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #a31515"&gt;}"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.CustomNavigate(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Content.virtualNavigation"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.AddRowType()&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.StartColumn(m =&amp;gt; m.Text)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.CustomColumnClass(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;GenericCssClasses&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.NoWrap)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.EndColumn()&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.EndRowType()&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.AddRowType()&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.StartColumn(m =&amp;gt; m.Text)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.CustomColumnClass(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;GenericCssClasses&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.NoWrap)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.EndColumn()&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.ChildCollection(m =&amp;gt; m.Children)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.EndRowType();&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;builder.Render()&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;ExtendedClientMenuFor&lt;/em&gt; &lt;em&gt;Html&amp;lt;T&amp;gt;&lt;/em&gt; extension declares the root menu items collection, the property that contains the level 0 menu items, and the menu data item property that contains the “action” to execute when the menu item is selected.Then, &lt;em&gt;ExtendedClientMenuFor&lt;/em&gt;&amp;nbsp; returns a fluent interface to continue the menu configuration. The root menu &lt;em&gt;ul&lt;/em&gt; tag contains the &lt;em&gt;mainmenu&lt;/em&gt; Css class&amp;nbsp; that defines some &amp;lt;ul&amp;gt; and &amp;lt;li&amp;gt; structural properties:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:620080d0-7114-4c06-b0b6-0f5adf9119d5" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"&gt;&lt;span style="background: #ffffff; color: #800000"&gt;ul.mainmenu&lt;/span&gt;&lt;br&gt;&lt;span style="background: #ffffff; color: #000000"&gt;{&lt;/span&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;padding&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;: &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;0&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;0&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;0&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;0&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;!important&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&amp;nbsp; &lt;/span&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;font-size&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;:&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;1.2em&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;br&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&amp;nbsp; &lt;/span&gt;&lt;br&gt;&lt;span style="background: #ffffff; color: #800000"&gt;ul.mainmenu&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;li&lt;/span&gt;&lt;br&gt;&lt;span style="background: #ffffff; color: #000000"&gt;{&lt;/span&gt;&lt;br&gt;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;margin&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;:&amp;nbsp; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;5px&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;7px&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;5px&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;7px&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;!important&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;&lt;br&gt;&lt;span style="background: #ffffff; color: #800000"&gt;ul.mainmenu&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #800000"&gt;ul&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; {&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;border&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;: &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;none&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;background-color&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;:&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;transparent&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; }&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The above definitions must be appended to the Content/Site.css file. You may experiment by changing some of them.&lt;/p&gt; &lt;p&gt;As a default sub-menus appear when the mouse hover their father menu item, but If the client device is a mobile device the call to &lt;em&gt;ActiveOnlyOnClick()&lt;/em&gt; change this behavior, and sub-menus are open on “click” or “tap”.&lt;/p&gt; &lt;p&gt;Then we declare which item property contains the target where to open links or virtual SPAView references, and the various menu items radiuses (see the picture that shows the three radiuses &lt;a href="http://www.mvc-controls.com/controls/menu" target="_blank"&gt;here&lt;/a&gt; ). &lt;/p&gt; &lt;p&gt;The way each menu item is rendered is defined by two templates, that are configured inside two &lt;em&gt;AddRowType()&lt;/em&gt;-&lt;em&gt;EndRowType()&lt;/em&gt; blocks. Both templates are based on the default menu row template, since no custom row template is defined, and both of them have an unique column that shows the menu item title. Each menu item title is contained in the &lt;em&gt;Text&lt;/em&gt; property of the underlying data item. The addition of the &lt;em&gt;GenericClasses.NoWrap&lt;/em&gt; Data Moving predefined Css class prevents menu item titles from wrapping. The only difference between the two templates is the &lt;em&gt;ChildCollection&lt;/em&gt; call in the second declaration, that causes the recursive rendering o all children sub items contained in the children &lt;em&gt;property&lt;/em&gt;. The two &lt;em&gt;AddRowType&lt;/em&gt; blocks define two knockout client templates. Their names are obtained by adding the postfixes ‘0’ and ‘1’ to the template base name “Basic_MenuItem” declared with &lt;em&gt;TemplateBaseName&lt;/em&gt;. It is good practice to give name of the type &lt;em&gt;&amp;lt;module name&amp;gt;_&amp;lt;a name&amp;gt;&lt;/em&gt; to all client templates used by controls declared inside SPAViews.&lt;/p&gt; &lt;p&gt;The first template is used for the menu items that can’t have children (their &lt;em&gt;Children&lt;/em&gt; property is a null observable) while the second template is used for the menu items that may have children (their &lt;em&gt;Children&lt;/em&gt; property is a possibly empty observable array). The selection of the right template is performed by the template selection function declared with &lt;em&gt;TemplateSelector&lt;/em&gt;. In our case the function is declared on line, but it may be also the name of a SPAView ViewModel method.&lt;/p&gt; &lt;p&gt;&lt;em&gt;CustomNavigate&lt;/em&gt; declares the custom navigation function we have already defined in the &lt;em&gt;MenuJs&lt;/em&gt; file.&lt;/p&gt; &lt;p&gt;That’s enough to see the menu working! Run the application and enjoy your first Data Moving SPA Menu!&lt;/p&gt; &lt;h2&gt;Adapting the Menu to the Current Page and to the Current Logged User&lt;/h2&gt; &lt;p&gt;Now, our last objective is adapting the menu to the logged user and to the actual SPAView that is in the main host. More specifically:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Each time the user changes the menu must display just the items the new user has the right to access, that is: if all sub-menus of a father menu item&amp;nbsp; are not visible and if the father menu item itself doesn’t connect to a SPAView the user may access, the father menu item&amp;nbsp; must be invisible  &lt;li&gt;The menu item that connects to the actual SPAView that is in the main host must appear in a “selected state”.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Both requirements may be achieved by letting the content ViewModel of our menu implements an interface, say, &lt;em&gt;IContextDependent&lt;/em&gt; with two methods:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;authorize(), that adapts the SPAView (our menu SPAView) to the authorizations of the current user.  &lt;li&gt;select(x), that informs the SPAView (our menu SPAView) that the SPAView x is currently in the main host. Where x is a string with the same format of the Link property of our menu data items.&amp;nbsp; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;In general we may handle several SPAViews that implements the &lt;em&gt;IContextDependent&lt;/em&gt; interface in a modular way as follows:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;We define a &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; resource handler with methods to register and unregister &lt;em&gt;IContextDependent&lt;/em&gt; implementations for being properly handled by the application.  &lt;li&gt;Each time a SPAView that implements &lt;em&gt;IContextDependent&lt;/em&gt;, is loaded it registers itself to the &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; resource handler, and then it unregisters itself when it is unloaded.  &lt;li&gt;Whenever the current user changes, the &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; resource handler is notified and calls the&lt;em&gt; authorize()&lt;/em&gt; method of all registered &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp;&amp;nbsp; implementations.  &lt;li&gt;Whenever the current SPAView in the main host changes the the &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; resource handler is notified and calls the&lt;em&gt; select(x)&lt;/em&gt; method of all registered &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp;&amp;nbsp; implementations.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;We may define the class that implements the &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; resource handler in the Views/Templates/Application/MainJs.cshtml file next to the definition of the &lt;em&gt;uiBlockInterface&lt;/em&gt; class:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e6e8a403-6819-40c8-adff-c3ac45eadc8b" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; iContextDependentHandler = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; () {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; registrations = [];&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;this&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.register = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (x) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;registrations.push(x);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;};&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;this&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.unregister = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (x) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; index = -1;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;for&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; i = 0; i &amp;lt; registrations.length; i++) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (registrations[i] == x) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;index = i;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;break&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (index &amp;gt; -1) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;array.splice(index, 1);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;};&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;this&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.select = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (x) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;for&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; i = 0; i &amp;lt; registrations.length; i++) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; item = registrations[i];&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (item.select) item.select(x);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;};&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;this&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.authorize = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; () {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;for&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; i = 0; i &amp;lt; registrations.length; i++) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; item = registrations[i];&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (item.authorize) item.authorize();&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Then, we add an instance of this classes to the &lt;em&gt;applicationModel.interfaces&lt;/em&gt; property, so that it is available within the &lt;em&gt;applicationModel&lt;/em&gt; itself and to all SPAViews:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:87254844-9eff-4929-964c-fac923d7ea26" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces.uiBlock = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; uiBlockInterface();&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces.mainHosts =&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;[applicationModel.MainContent, applicationModel.MenuContent];&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces.contextHandler = &lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//&amp;lt;-add here&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; iContextDependentHandler();&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;iContextDependent.select&lt;/em&gt; method must be called each time a new SPAView is placed in the application main host. Accordingly, it may be called in the main host &lt;em&gt;mainAfterRender&lt;/em&gt; that is defined as an &lt;em&gt;applicationModel&lt;/em&gt; method in the Views/Templates/Application/MainJs.cshtml file:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e9b63dd5-9c46-4656-a0ae-33cf0b182c1c" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.mainAfterRender = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (x, y) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//start added code&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (y &amp;amp;&amp;amp; mvcct.ko.dynamicTemplates.isBaseViewModel(y))&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces.contextHandler&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.select(y.module + &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;'.'&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; + y.view)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;else&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces.contextHandler&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.select(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;null&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//end added code&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;$(mvcct.core.filterHtml(x)).fadeOut(0).fadeIn(400);&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;};&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;if&lt;/em&gt; checks that the &lt;em&gt;module&lt;/em&gt; and &lt;em&gt;view&lt;/em&gt; properties are actually defined, otherwise a &lt;em&gt;null&lt;/em&gt; value passed to the &lt;em&gt;select&lt;/em&gt; method simply de-selects any previously selected SPAView.&lt;/p&gt; &lt;p&gt;The &lt;em&gt;iContextDependent.authorize&lt;/em&gt; method must be called each time the logged user changes. The instruction that initializes the authorization system in the Views/Templates/Application/MainJs.cshtml file accepts an array of observables, and functions that are automatically notified whenever the user changes. This is the right place for calling our &lt;em&gt;authorize&lt;/em&gt; method:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d8353988-52e3-4821-bd66-1ce24c9d7b60" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;mvcct.ko.dynamicTemplates.enableAuthorizationManager(&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;Url.Content(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"~/api/Account/CurrentUser"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;Url.Content(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"~/api/Account/Logout"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; () {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt; on logout &lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;,&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;[applicationModel.MainContent,&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;applicationModel.interfaces.contextHandler.authorize&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//&amp;lt;-add here&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;] &lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt;all observables to refresh when the user changes&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;);&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&lt;em&gt;&lt;/em&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;em&gt;iContextDependent.register&lt;/em&gt; and &lt;em&gt;iContextDependent.unregister&lt;/em&gt; must be called in the Views/Templates/Basic/MenuJs.cshtml JavaScript file associated with our Menu SPAView.&lt;/p&gt; &lt;p&gt;The right place to call &lt;em&gt;iContextDependent.register&lt;/em&gt; is the &lt;em&gt;processInput&lt;/em&gt; method that is called each time a SPAView is loaded, while the right place to call &lt;em&gt;iContextDependent.unregister&lt;/em&gt; is the &lt;em&gt;beforeRemove&lt;/em&gt; method that is called before the SPAView is unloaded:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cbcaaf7d-a8c8-4942-b95f-eef32e6359f1" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;vm.processInput = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (nodes) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt; Code here is executed each time the page is loaded.&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;Virtual page inputData must be processed here &lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;vm._interfaces.contextHandler.register(vm.Content);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;modifyDomOnLoad(vm, nodes);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;};&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;vm.beforeRemove = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; () {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt; Insert here clean up code to be&amp;nbsp; executed &lt;/span&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #006400"&gt;when the page is unloaded&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;vm._interfaces.contextHandler.unregister(vm.Content);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;cleanupDomOnUnload(vm);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;};&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now our &lt;em&gt;vm.Content&lt;/em&gt; ViewModel must implement&amp;nbsp; the &lt;em&gt;IContextDependent&lt;/em&gt;&amp;nbsp; interface. You may place the interface definition immediately after the&lt;em&gt; vm.Content.virtualNavigation&lt;/em&gt; method we defined before:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a762cfb8-17b4-4b45-b66c-8b230ca70dd7" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; currentSelected = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;null&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;vm.Content.select = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (action) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (!action) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;currentSelected = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;null&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (currentSelected)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;mvcct.html.menu.selected(currentSelected, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; res =&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;selectMenu(&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;ko.utils.unwrapObservable(vm.Content.Children),&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;action);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (!res &amp;amp;&amp;amp; currentSelected) &lt;/span&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;mvcct.html.menu.selected(currentSelected, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;currentSelected = res;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;};&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;vm.Content.authorize = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; () {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;authorizeMenu(&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;mvcct.ko.dynamicTemplates.authorizationManager(),&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;vm.Content.Children);&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;vm.Content.authorize();&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Both methods call two private recursive functions that traverse the menu data items hierarchy to do their job.&lt;/p&gt; &lt;p&gt;The &lt;em&gt;currentSelected&lt;/em&gt; private variable contains the menu data item that is currently selected, if any, otherwise, &lt;em&gt;null&lt;/em&gt;. If a &lt;em&gt;null&lt;/em&gt; action is passed, &lt;em&gt;currentSelected&lt;/em&gt; is set to &lt;em&gt;null&lt;/em&gt; and any previously selected menu item is unselected by calling&lt;em&gt; mvcct.html.menu.selected(currentSelected, false)&lt;/em&gt;. &lt;/p&gt; &lt;p&gt;Otherwise the recusive &lt;em&gt;selectMenu&lt;/em&gt; function tries to locate a menu data item matching the &lt;em&gt;action&lt;/em&gt; string. If such a data item is found the menu item it is bound to is set in the selected state by calling: &lt;em&gt;mvcct.html.menu.selected(item, true)&lt;/em&gt; and the data item itself is returned in the &lt;em&gt;res&lt;/em&gt; variable, so it may substitute the previous &lt;em&gt;currentSelected&lt;/em&gt;. If the &lt;em&gt;selectMenu&lt;/em&gt; recursive search fails, &lt;em&gt;null&lt;/em&gt; is returned in &lt;em&gt;res&lt;/em&gt;, and any previously selected item is unselected by calling &lt;em&gt;mvcct.html.menu.selected(currentSelected, false)&lt;/em&gt;. &lt;/p&gt; &lt;p&gt;The authorize method immediately calls the recursive private function &lt;em&gt;authorizeMenu&lt;/em&gt; passing it the current authorization manager, and the level 0 menu data items. The &lt;em&gt;authorizeMenu&lt;/em&gt; function traverses the menu data items hierarchy and checks possible links to SPAView against the authorization manager to verify if the SPAView may be accessed by the current user. In case the SPAView referred by a menu data item cannot be accessed by the user, the data item rendering is prevented by setting its &lt;em&gt;_destroy&lt;/em&gt; property to &lt;em&gt;true&lt;/em&gt;. If a menu item x has the only purpose of showing its children sub-items, and if all its children have &lt;em&gt;_destroy&lt;/em&gt; set to &lt;em&gt;true&lt;/em&gt; also the &lt;em&gt;_destroy&lt;/em&gt; property of x is set to &lt;em&gt;true&lt;/em&gt;, since it is completely un-useful.&lt;/p&gt; &lt;p&gt;The private functions &lt;em&gt;selectMenu&lt;/em&gt;&amp;nbsp; and &lt;em&gt;authorizeMenu&lt;/em&gt; may be placed in the read-only private members area immediately before the &lt;em&gt;mvcct.core.moduleResult&lt;/em&gt; call:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9411f7b3-154a-43eb-8d8b-3e8ef100f8fb" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt;Insert private functions and private readonly variables here&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; selectMenu(children, action, target) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;for&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; i = 0; i &amp;lt; children.length; i++) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; item = children[i];&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (action == ko.utils.unwrapObservable(item.Link) &amp;amp;&amp;amp;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;(!target ||&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;target ==&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;(ko.utils.unwrapObservable(item.Target) || &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"0"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;))) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;mvcct.html.menu.selected(item, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; item;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; iChildren = ko.utils.unwrapObservable(item.Children);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (iChildren) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; child = selectMenu(iChildren, action, target);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (child) &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; child;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; authorizeMenu(authorizationManager, obsChildren) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; children = ko.utils.unwrapObservable(obsChildren);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (!children || children.length == 0) &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; hasChildren = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; aChange = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;for&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; i = 0; i &amp;lt; children.length; i++) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; item = children[i];&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; action = ko.utils.unwrapObservable(item.Link);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; virtualLink = action &amp;amp;&amp;amp;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;action.charAt(0) != &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;'#'&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &amp;amp;&amp;amp;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;action.charAt(0) != &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;'@@'&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &amp;amp;&amp;amp;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;action.charAt(0) != &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;'/'&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &amp;amp;&amp;amp;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;action.indexOf(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"http"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;) != 0 &amp;amp;&amp;amp;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;action.indexOf(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"mailto"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;) != 0;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; authorized = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (virtualLink) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; parts = action.split(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;'.'&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;authorized = &lt;/span&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;!authorizationManager.verifyAuthorization(&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; mvcct.ko.dynamicTemplates&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.virtualReference(parts[0], parts[1])&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;else&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; authorized = action;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;authorized = authorized || &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (authorized) authorized = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; childrenAuthorized =&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;authorizeMenu(authorizationManager, item.Children);&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;authorized = authorized || childrenAuthorized;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; ((item._destroy || &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;) != !authorized) {&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;item._destroy = !authorized;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;aChange = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (item._destroy) mvcct.ko.unfreeze(item);&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (authorized) hasChildren = &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (aChange) obsChildren.valueHasMutated();&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; hasChildren;&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@*&lt;/span&gt;&lt;span style="background: #ffffff; color: #006400"&gt;End of private area&lt;/span&gt;&lt;span style="background: #ffff00; color: #000000"&gt;*@&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;mvcct.core.moduleResult(&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (vm) {&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;...&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;...&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;...&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;It is worth to point out that each time we make invisible a menu item we call the &lt;em&gt;mvcct.ko.unfreeze&lt;/em&gt; to release any possible cached template, since most of Data Moving controls cache templates to improve performance.&lt;/p&gt; &lt;p&gt;Now the context dependent menu is ready. Whenever you navigate to a SPAView that is referenced in a menu item that menu item will become visible and will appear in a selected state:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/SelectedMenu.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SelectedMenu" border="0" alt="SelectedMenu" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/SelectedMenu_thumb.png" width="539" height="173"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;When a menu item get the focus the focus style overrides its “selected color” (this is due to the way bootstrap handles the focus style), if you don’t like this behavior you may change it by appending the following Css rule to the Site.css file:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:44895477-366d-4742-a266-849d90db91d2" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #800000"&gt;.mvcct-menu-item-selected:focus{&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;background-color&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;: &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;#d9edf7&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;!important&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;;&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;border&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;:&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;2px&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;solid&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;yellow&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;!important&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Where background-color must match “selected color” that in the case of&amp;nbsp; bootstrap is the “alert-info” Css class background-color.&lt;/p&gt; &lt;p&gt;If a permanently opened sub-menu is not acceptable in your application, you may customize the Css class that is added to all menu items on the path to the selected item by calling the &lt;em&gt;ItemSelection&lt;/em&gt; method of the menu fluent interface. In the example below, a yellow border is added to all items on the path to the selected&amp;nbsp; item instead of leaving them permanently in the opened state:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:85e051e9-8ad9-49ff-8205-d9b0be0fad04" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@model &lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;MVCControlsToolkit.Controls.&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;SimpleMenuItem&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@{&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; builder = Html.ExtendedClientMenuFor(&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;m =&amp;gt; m.Children, m =&amp;gt; m.Link,&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; { @class = &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"mainmenu"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; });&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; (&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;HttpContext&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.Current.Request.Browser.IsMobileDevice)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;{&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;builder = builder.ActiveOnlyOnClick();&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;builder.Target(m =&amp;gt; m.Target)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.Radiuses(0.5f, 1f, 0.5f)&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.ItemSelection(structurePathSelectClass: &lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"light-select"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;&lt;span style="background: #ffffff; color: #008000"&gt;//&amp;lt;-&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.TemplatesBaseName(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Basic_MenuItem"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.TemplateSelector(&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;@"function(x){&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #a31515"&gt;return (x.Children.peek() ?&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #a31515"&gt;'Basic_MenuItem1' : 'Basic_MenuItem0');&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #a31515"&gt;}"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.CustomNavigate(&lt;/span&gt;&lt;span style="background: #ffffff; color: #a31515"&gt;"Content.virtualNavigation"&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.AddRowType()&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.StartColumn(m =&amp;gt; m.Text)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.CustomColumnClass(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;GenericCssClasses&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.NoWrap)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.EndColumn()&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.EndRowType()&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.AddRowType()&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.StartColumn(m =&amp;gt; m.Text)&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.CustomColumnClass(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af"&gt;GenericCssClasses&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.NoWrap)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.EndColumn()&lt;/span&gt;  &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;.ChildCollection(m =&amp;gt; m.Children)&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;.EndRowType();&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt;  &lt;li&gt;&lt;span style="background: #ffff00; color: #000000"&gt;@&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;builder.Render()&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f3f48eb9-1fa8-4e84-9c19-dd36b05eb47f" class="wlWriterSmartContent"&gt; &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #800000"&gt;.light-select{&lt;/span&gt;  &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="background: #ffffff; color: #000000"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #ff0000"&gt;border&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;:&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;2px&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;solid&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;yellow&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff"&gt;!important&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000"&gt;; &lt;/span&gt; &lt;li&gt;&lt;span style="background: #ffffff; color: #000000"&gt;}&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/AlternateSelect.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="AlternateSelect" border="0" alt="AlternateSelect" src="http://www.mvc-controls.com/Media/Default/Windows-Live-Writer/Data-Moving-SPA-with-a-Context-Dependent_F3F6/AlternateSelect_thumb.png" width="539" height="176"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In this case the “selected color” on the menu item linking to “Page 4” becomes visible only if you hover the yellow-border “private area”.&lt;/p&gt; &lt;p&gt;You may also add a &lt;em&gt;breadcrumb&lt;/em&gt; and modify the menu &lt;em&gt;select&lt;/em&gt; method to update the breadcrumb, too. &lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;font size="3"&gt;That’s all for now!&lt;/font&gt;&lt;/strong&gt; The full code is available in the “ContextDependentMenu” file of the &lt;a href="https://datamovingexamples.codeplex.com/releases" target="_blank"&gt;Data Moving Plugin Examples Codeplex site download&amp;nbsp; area.&lt;/a&gt; The Visual studio solution must be activated by installing the&amp;nbsp; DataMovingPlugin5Examples.x.x.x.nupkg file you get with the product.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;font size="3"&gt;Francesco&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;</description><pubDate>Sat, 08 Feb 2014 20:13:02 GMT</pubDate><guid isPermaLink="true">http://datamoving.mvc-controls.com:80/blog/data-moving-spa-with-a-context-dependent-menu</guid></item><item><title>Data Moving Plug-in SPA View Engine: Handling Contextual Information and User Authorization</title><link>http://datamoving.mvc-controls.com:80/blog/data-moving-plug-in-spa-view-engine-handling-contextual-information-and-user-authorization</link><description>&lt;h3&gt;&lt;a href="http://www.mvc-controls.com/blog/data-moving-plug-in-spa-view-engine"&gt;Data Moving Plug-in SPA View Engine&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div style="padding-bottom: 1ex; background-color: gray; padding-left: 1ex; padding-right: 1ex; color: black; padding-top: 1ex"&gt; &lt;p&gt;This is the second article about new Data Moving Plug-in SPA View Engine, so the previous article is a pre-requisite for reading it.&lt;/p&gt; &lt;p&gt;In any MVVM (Model View ViewModel)&amp;nbsp; SPA (Single Page Applications) dependencies among the View-ViewModel pairs, and dependencies of each View-ViewModel pair on the global state of the application may undermine the modularity and stability of the whole application: &lt;/p&gt; &lt;ol&gt; &lt;li&gt;When a View-ViewModel pair is released&amp;nbsp; we MUST be sure that all pointers to data structures inside the pair are removed, otherwise we may cause memory leaks, and hard to find bugs. For instance, if an event handler maintains a reference to a disposed pair, it may trigger unexpected behaviors each time the event is fired. &lt;br&gt;As a consequence&amp;nbsp; data structures inside a View-ViewModel pair can’t depend on observables that are outside of the pair. Accordingly, external dependencies &lt;u&gt;can’t be updated dynamically by using the observer pattern&lt;/u&gt;, &lt;u&gt;but must be copied&lt;/u&gt; inside the pair by framework components that are run ONLY on pairs that for sure have not been released. The best time to perform such an update operation is immediately before a pair is rendered since released pairs are not rendered anymore. However, this implies also that we need to force manually re-rendering of pairs displayed on the screen when a dependency changes.  &lt;li&gt;In theory each View-ViewModel pair might contain reference to global application data structures without undermining the application stability, since when the pair is released these references die with the pair. Thus, we might use global data structures for the communication of each View-ViewModel pair with their environment. Unluckily, the use&amp;nbsp; of global variables is an anti-pattern that is known to undermine the modularity of an application. In fact, a change in the global data structures might invalidates all modules! Moreover, modules that depend on global variable are not re-usable in different contexts.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The Data Moving Plug-in View Engine faces all above problems by concentrating the contextual dependencies in &lt;em&gt;context rules&lt;/em&gt; that are run immediately before rendering a View-ViewModel pair. Context rules are run on the ViewModel being rendered till a matching rule is found. The matching rule collects global information the View-ViewModel pair might depend on both to&amp;nbsp; build a &lt;em&gt;context object&lt;/em&gt; and to fill some ViewModel properties. The information copied by the context rules in the ViewModel may include interface objects that may be used by the ViewModel methods to manipulate the global application state. This way each template ViewModel pair may cooperate with the remainder of the application while keeping its modularity. In case of virtual pages the interface passed to a ViewModel usually depends not only on the module, and local template name, but also on the role assigned to the virtual page by the virtualReference object that required the page to the page store. The virtual page role is available in its role property.&lt;/p&gt; &lt;p&gt;This way all burden of interpreting the external environment falls on the contextual rules and doesn’t undermine the modularity of the View-ViewModel pairs: View-ViewModel pairs may be used in different contexts by simply changing or adding some context rules, without modifying their code.&lt;/p&gt; &lt;p&gt;The purpose of the &lt;em&gt;context object&lt;/em&gt; is twofold:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;The &lt;em&gt;context ob&lt;/em&gt;ject&amp;nbsp; contains all information needed&amp;nbsp; for selecting the right version of the template-AMD module pair to instantiate. In fact, the action methods that deploys both the templates and the AMD of each module may accept parameters such as the name of the logged user and the selected culture, to adapt the module to the context. Such parameters MUST&amp;nbsp; be inserted in the URL because both the AMD and the templates are cached by the browser, thus the insertion of the contextual parameters in the URL is the only way to force the browser to cache different copies for each different set of parameters. &lt;br&gt;The context object may contain also a redirect directive that forces the loading of a completely different view (belonging to the same module or to a different module). This capability is used to redirect an user to the login virtual page when he/she tries to access a virtual page that is not available for anonymous users. Moreover, after log-in the insertion of the username among the parameters that are sent to the server allows the personalization of the template/AMD modules to the actual privileges of the user.  &lt;li&gt;The &lt;em&gt;context ob&lt;/em&gt;ject contains a synthesis of global information the View-ViewModel pair depends on that is used to decide if the pair needs to be re-rendered, or not. In fact, virtual pages retrieved from the &lt;em&gt;page store&lt;/em&gt; normally are not&amp;nbsp; re-rendered but used as they were left the last time they were used. However, if the context object created when the pair was rendered differs from the current context the pair is re-rendered to adapt it it to the new context. More specifically, re-rendering forces the re-application of the javascript function defined in the AMD module to the ViewModel, that takes advantage of the information about the external environment&amp;nbsp; written in the ViewModel properties by the context rules to adapt the View-ViewModel pair to the new situation. In case the context rules add different parameters to the URL, or redirect to a different View the ViewModel is completely reset and filled with new content and rendered with a different template.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Below a context rule that handles a page that is available only for logged-in users:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:be70fb94-3a5a-422b-956b-12ac4d47174f" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.addContextRule(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (data, cb) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; currUser = mvcct.ko.dynamicTemplates.authorizationManager().currentUser();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (data.module == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;People&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!currUser) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;cb.redirect(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;cb.add(currUser)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;              &lt;span style="background:#ffffff;color:#000000"&gt;.addTicket();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;A new context rule is added by passing a function to the &lt;em&gt;mvcct.ko.dynamicTemplates.addContextRule&lt;/em&gt; method. This function receives the ViewModel and a context builder object as parameters. The function is expected to return &lt;em&gt;true&lt;/em&gt; when its pre-concitions are satisfied and &lt;em&gt;false&lt;/em&gt; otherwise. Inside the context rule we may build the context object by using the fluent interface of the context builder object.&lt;/p&gt; &lt;p&gt;In our case the preconditions of the rules are satisfied only if the module name is “People”. In more complex applications having several modules that require login, a simple solution is to give them a common name prefix: something like “secure_people”, so that context rules may just check this prefix.&lt;/p&gt; &lt;p&gt;In our case the rule verifies if the user is logged in with a call to the &lt;em&gt;authorizationManager&lt;/em&gt;. If the user is not logged, we insert a “redirect to the login virtual page” request into the context object by calling the &lt;em&gt;redirect&lt;/em&gt; method of the context builder.&lt;/p&gt; &lt;p&gt;If the user is logged, instead, we add the username and the authentication ticket to the url. In this case we don’t&amp;nbsp; write anything in the ViewModel, since the partial views that implement the templates and AMD will take care of adapting the content deployed to the logged user.&lt;/p&gt; &lt;p&gt;The addition of the authorization ticket to the URL must be done if and only if the AMD and template contain sensitive information that must be protected from unauthorized&amp;nbsp; accesses. The insertion of the authorization ticket in the URL DE FACTO prevents the caching of the templates and AMD in the browser cache, since the authorization ticket usually has a short life. Moreover, caching MUST be explicitly prohibited with an adequate &lt;em&gt;OutputCache&lt;/em&gt; attribute to protect the sensitive information from malicious users that might manipulate the Browser Cache. &lt;/p&gt; &lt;p&gt;For the above reasons, it is advised to avoid the insertion of the authorization ticket in the URL, and to it is advised to require any sensitive information with a subsequent ajax call to the server. In this case the username&amp;nbsp; passed in the URL may be used just to adapt the graphics of the virtual page to the logged user by removing links to pages that the user is not authorized to visit, and by customizing the virtual page with some user preference the user might have provided someway.&lt;/p&gt; &lt;p&gt;The &lt;em&gt;add&lt;/em&gt; context builder method stacks the strings passed as parameters in the URL one after the other, before the module name. For instance if after the &lt;em&gt;add(currUser&lt;/em&gt;) we perform another add for the selected culture we get URLs like: …./en-US/john32/People/ for the templates and …./en-US/john32/People.js for the AMD. In case we require also the addition of the authorization ticket, the ticket is appended just to AMD module URL,: …./en-US/john32/People.js?ticket=&amp;lt;authorization ticket&amp;gt;. The request for the templates doesn’t need to include explicitly the authorization ticket in the URL, since this request uses cookies and consequently it is authenticated with the authorization ticket contained in the Asp.net authorization cookie. &lt;/p&gt; &lt;p&gt;The context builder object contains also other two add methods, namely:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;em&gt;addv(x):&lt;/em&gt; it stacks the string passed as parameter before the template local name, instead of before the module name. This means that the module request remain unchanged, but a different template that is contained in the same module is requested. For instance if we stack the “Logged” string with &lt;em&gt;addv&lt;/em&gt;, to the view named “List” contained in the “People” module, then&amp;nbsp; the request for the People module remains unchanged: …./People/ for the templates and …./People.js for the AMD, but the template used to render the ViewModel will be People/Logged/List instead of People/List.  &lt;li&gt;&lt;em&gt;addc(x)&lt;/em&gt;: it just modifies the context object without modifying neither the module name nor the view name. All strings passed with &lt;em&gt;addc&lt;/em&gt; are stacked together to record a dependency from the environment. This way, when the above strings change the difference in the context forces the re-rendering of the View-ViewModel pair. Normally &lt;em&gt;addc&lt;/em&gt; is used together with changes in some ViewModel properties. This way, &lt;em&gt;addc&lt;/em&gt; forces the re-rendering of the View-ViewModel pair, and the re-rendering of the pair produces a different result because of the ViewModel modifications.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Below a set of context rules adequate for handling user authorization:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2a87389d-d0d9-48d1-ade6-fe1a31fe5736" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.addContextRule(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (data, cb) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ((data.view == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; || data.view == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Register&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ) &amp;amp;&amp;amp; data.module == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (mvcct.ko.dynamicTemplates.authorizationManager().currentUser()) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;cb.vadd(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Logged&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.addContextRule(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (data, cb) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; currUser = mvcct.ko.dynamicTemplates.authorizationManager().currentUser();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (data.module == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;People&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!currUser) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;cb.redirect(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;cb.add(currUser)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                  &lt;span style="background:#ffffff;color:#000000"&gt;.addTicket();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.addContextRule(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (data, cb) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; currUser = mvcct.ko.dynamicTemplates.authorizationManager().currentUser();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (mvcct.ko.dynamicTemplates.isBaseViewModel(data)) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                          &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;//force re-rendering of all virtual pages &lt;/span&gt;&lt;/li&gt; &lt;li&gt;                          &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000"&gt;//if logged user changes&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;cb.cadd(currUser || &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;})();&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The first rule changes the view used to render the Login and Register virtual pages in case the user is already logged, by adding a view prefix with &lt;em&gt;vadd&lt;/em&gt;. The second rule is the rule we already analyzed for redirecting anonymous users to the login page when they need to access pages that require login.&lt;/p&gt; &lt;p&gt;Finally, the last rules is fired for all virtual pages that doesn’t&amp;nbsp; satisfy the previous rules. The &lt;em&gt;mvvct.ko.dynamicTemplates.isBaseViewModel&lt;/em&gt; verifies that data is a virtual page ViewModel. This rules, requires the re-rendering of a virtual whenever the logged user changes by means of the &lt;em&gt;cadd&lt;/em&gt; method. This re-rendering is necessary because of page headers that might depend on the logged use (for instance the login/logout link). &lt;/p&gt; &lt;p&gt;It is worth to point out that re-rendering doesn’t imply necessarily any loss of data that might be contained in the ViewModel. Data are reset just when a virtual page is rendered the first time, or when it has been re-rendered because of a change of the template/javscript selected. Thus, re-rendering caused by a &lt;em&gt;cadd&lt;/em&gt; doesn’t cause any loss of data but just a refresh of the contextual information.&lt;/p&gt; &lt;p&gt;The javascript code associated to any template is informed about the need to re-initialize the whole ViewModel through the _&lt;em&gt;initialized&lt;/em&gt; boolean property that is added to each ViewModel. When the javascript code initializes a ViewModel it sets this property to &lt;em&gt;true&lt;/em&gt;. The property is automatically re-set to &lt;em&gt;false&lt;/em&gt; whenever the framework realizes that the ViewModel needs to be re-initialized. Below an example of usage of the &lt;em&gt;_initialized&lt;/em&gt; property:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:89de9a18-d4ca-41d4-b651-e06b26834ce1" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;   &lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.JavaScriptDefine(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;viewModel&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,  &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;HumanResourcesViewModel&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;()) &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; afterRender(nodes, vm) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;vm.updater.options({&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;onUpdateComplete: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;$.unblockUI();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;},&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;htmlStatusMessages: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (statusCode, statusText) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (statusCode == 401) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Unauthorized&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; statusText;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;},&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;updatingCallback: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;$.blockUI();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;vm._utilities.humanResourcesRM.options({&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;htmlStatusMessages: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (statusCode, statusText) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (statusCode == 401) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Unauthorized&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; statusText;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.core.moduleResult(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (vm) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!vm._initialized) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm._initialized = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm._utilities = {};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm._utilities.clientSubmit = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (id, jTarget, operation) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (operation == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;operation-submit&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; jForm = jTarget.closest(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;form&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (jForm.validate().form()) vm.updater.update(jForm);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm._utilities.selectItem = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (act) { act.addClass(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;item-selected&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;); };&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm._utilities.unselectItem = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (prev, act) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;prev.removeClass(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;item-selected&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;); &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm.Content = ko.mapping.fromJS(viewModel);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm._title = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.HumanResourcesListTitle&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; { afterRender: afterRender };&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;})();  &lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;In the example above, if re-rendering is required because of a &lt;em&gt;cadd-&lt;/em&gt;only context change the template is re-rendered, and the &lt;em&gt;afterRender&lt;/em&gt; function is re-executed on the newly created html, but all ViewModel building is saved because it has been enclosed within an (&lt;em&gt;!vm_initialized)&lt;/em&gt; if.&lt;/p&gt; &lt;p&gt;The context object may be accessed also in the javascript code associated to a template by calling the function: &lt;em&gt;mvcct.ko.dynamicTemplates.getContext(vm)&lt;/em&gt;.&amp;nbsp; In the example below the context object is used to decide which javascript module to call for initializing the ViewModel:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:afc87ada-c6e4-4b4c-9344-b7ed84e185da" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;define(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.IncludeStaticJsModules(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/MenuJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/RegisterJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/LoginJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/LogoutJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/RegistredJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; mvcct.core.withIncludedModules(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (menuF, registerF, loginF, logoutF, registredF) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (vm, viewName) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; context = mvcct.ko.dynamicTemplates.getContext(vm);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vprefix = context ? context.vprefix : &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (viewName == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Menu&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; menuF(vm);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (viewName == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Register&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; vprefix == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Logged&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ? &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;registredF(vm) : registerF(vm);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (viewName == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; vprefix == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Logged&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ? &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;logoutF(vm) : loginF(vm);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;});  &lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;In fact in case the user is logged we not only need completely different templates, but also a completely different initialization code, since the underlying data are completely different.&lt;/p&gt; &lt;p&gt;In order to add multi-lingual support to the context rules of our previous example it is enough to add a &lt;em&gt;.add(&amp;lt;language string&amp;gt;)&lt;/em&gt;&amp;nbsp; call to all our context rules. The &amp;lt;language string&amp;gt; may be extracted by the cookie we use to record the user language settings.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;In order to add support for user authorization we need also to initialize properly the &lt;em&gt;authorizationManager&lt;/em&gt;, and to implement&amp;nbsp; the action methods, to login, logout, register, and to verify the name of the currently logged user. The Register action method is not conceptually different from any standard register method. Below, all other methods:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8886a516-5823-4a30-ac08-e866398fbd1f" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;[&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OutputCache&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(NoStore=&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, Duration = 0)]&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ActionResult&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Logout()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (HttpContext.User.Identity.IsAuthenticated) &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;FormsAuthentication&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.SignOut();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Json(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;JsonRequestBehavior&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.AllowGet);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;[&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;OutputCache&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(NoStore = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, Duration = 0)]&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ActionResult&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; CurrentUser()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (HttpContext.User != &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &amp;amp;&amp;amp; HttpContext.User.Identity.IsAuthenticated) &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Json(HttpContext.User.Identity.Name, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;JsonRequestBehavior&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.AllowGet);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Json(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;JsonRequestBehavior&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.AllowGet);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ActionResult&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Login(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;LoginModel&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; model)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; rb = &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ResponseBuilder&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.NewResponseBuilder(model, ModelState);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; valueToReturn = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (ModelState.IsValid)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Membership&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.ValidateUser(model.Username, model.Password))&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SPASecurity&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.SetAuthCookie(model.Username, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;valueToReturn = model.Username;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;ModelState.AddModelError(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;The user name or password provided is incorrect.&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Json(rb.GetResponse(additionalData: valueToReturn));&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The first two methods are self-explanatory, while the login action method differs from a standard Mvc Login method just for the use of the &lt;em&gt;SPASecurity.SetAuthCookie&lt;/em&gt; method instead of the &lt;em&gt;FormsAuthentication.SetAuthCookie&lt;/em&gt; method.&lt;/p&gt; &lt;p&gt;The login model is sent to the server by a &lt;em&gt;viewModelUpdatesManager&lt;/em&gt;, that takes care also of dispatching possible server errors(such as the login failure):&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fa0e6c56-dea1-4e05-acb7-dc8ba096c339" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;mvcct.core.moduleResult(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (vm) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!vm._initialized) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;vm._initialized = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;vm.undoRedo = mvcct.core.undoRedo();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;vm.undoRedo.with(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;vm.Content = ko.mapping.fromJS(loginForm);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; updaterOptions = {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;onUpdateStart: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;$.blockUI();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;},&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;onUpdateComplete: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (e, result, status) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (e.success) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;vm.undoRedo.reset();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;vm.Content.Password(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; redirect = vm.hasRedirect();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.authorizationManager()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;.declareUser(result.additionalData, !redirect);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!redirect)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="background:#ffffff;color:#000000"&gt;vm.goTo(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; mvcct.ko.dynamicTemplates.virtualReference(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Menu&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;));&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;$.unblockUI();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;vm.updater = mvcct.viewModelUpdatesManager(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Action(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;vm,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Content&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;vm.Content,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;updaterOptions);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;vm._title = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.LoginTitle&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; {afterRender: afterRender };&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;In the &lt;em&gt;onUpdateComplete&lt;/em&gt; callback, in case of success,&amp;nbsp; we reset the &lt;a href="http://www.mvc-controls.com/features/forms"&gt;undo-redo stack of the Data Moving Plug-in Form&lt;/a&gt;, reset the password property of the ViewModel, then we declare the new user (contained in the &lt;em&gt;additionalData&lt;/em&gt; property of the response) to the &lt;em&gt;authorizationManager&lt;/em&gt;. If the ViewModel rendered the login page because of a redirect context directive,&amp;nbsp; the ViewModel will be automatically re-initialized to display the original content required as soon as the new user is declared to the authorizationManager. Otherwise, we pass &lt;em&gt;false&lt;/em&gt; in the user declaration, which requires a silent user change. As a consequence no re-rendering of the current virtual page is attempted. Then we go manually to the home page by calling the &lt;em&gt;goTo&lt;/em&gt; method of the virtual page (see the previous post of the series for more details on the &lt;em&gt;goTo&lt;/em&gt; method).&lt;/p&gt; &lt;p&gt;The call to the &lt;em&gt;Logout&lt;/em&gt;&amp;nbsp; and &lt;em&gt;CurrentUser&lt;/em&gt; action methods are handled automatically by the by the &lt;em&gt;logout(onError)&lt;/em&gt; and &lt;em&gt;updateUserFromserver(onServerResponse, onError)&lt;/em&gt; methods of the &lt;em&gt;authorizationManager&lt;/em&gt;, that are called from within the click hanlders of the &lt;em&gt;logout&lt;/em&gt; and &lt;em&gt;refresh&lt;/em&gt; links that are in the header of each virtual page:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/WindowsLiveWriter/DataMovingPluginSPAViewEngineHandlingCon_FD3F/HeaderLinks.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="HeaderLinks" border="0" alt="HeaderLinks" src="http://www.mvc-controls.com/Media/Default/WindowsLiveWriter/DataMovingPluginSPAViewEngineHandlingCon_FD3F/HeaderLinks_thumb.png" width="201" height="37"&gt;&lt;/a&gt; &lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4a7d0a55-45d2-4de3-baef-a88e29e48b8f" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;vm.refresh = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.authorizationManager().updateUserFromserver();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;vm.logout = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.authorizationManager().logout();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;The authorization managers is initialized with the call:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8ba27eba-6446-4bce-8f35-88995e9bbdd3" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.enableAuthorizationManager(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Action(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;CurrentUser&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Action(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Logout&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;applicationModel.CurrentPage&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The first argument is the link of the &lt;em&gt;CurrentUser&lt;/em&gt; action method, the second one the link of the Logout method,&amp;nbsp; the third argument, if provided, is an &lt;em&gt;onLogout&lt;/em&gt; callback while the fourth argument is a single observable or an array of observables that must be refreshed when the user changes. In our case we passed as fourth argument&amp;nbsp; our unique container of all virtual pages. In a more complex application that hosts several physical pages in the same physical page we might have passed an array containing several observables used as virtual page containers.&lt;/p&gt; &lt;p&gt;In all action methods that deploy templates/AMD only to logged users we must call the method to &lt;em&gt;SPASecurity.ValidatedUser&lt;/em&gt; to validated the user received as parameter:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f23f42fe-877c-442f-a311-fe90b838a45b" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ActionResult&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; People(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; user, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;bool&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; isJs, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ticket)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; module = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;People/Main&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SPASecurity&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.ValidateUser(user, ticket)) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;HttpUnauthorizedResult&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (isJs) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.MinifiedJavascriptResult(module + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; PartialView(module, user+&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;/People&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp; &lt;p&gt;The &lt;em&gt;SPASecurity.ValidatedUser&lt;/em&gt; method attempts validation with both the asp.net authorization cookie and with the ticket passed as argument.  &lt;p&gt;&lt;strong&gt;That’s all for now!&amp;nbsp; A video showing the Data Moving Plug-in SPA View Engine is available &lt;a href="http://www.mvc-controls.com/features/spa-framework"&gt;here&lt;/a&gt;.&lt;/strong&gt;  &lt;p&gt;&lt;strong&gt;Francesco&lt;/strong&gt; &lt;/p&gt;&lt;/div&gt;</description><pubDate>Sun, 08 Sep 2013 22:01:36 GMT</pubDate><guid isPermaLink="true">http://datamoving.mvc-controls.com:80/blog/data-moving-plug-in-spa-view-engine-handling-contextual-information-and-user-authorization</guid></item><item><title>Data Moving Plug-in SPA View Engine</title><link>http://datamoving.mvc-controls.com:80/blog/data-moving-plug-in-spa-view-engine</link><description>&lt;h3&gt;&lt;a href="http://www.mvc-controls.com/blog/data-moving-plug-in-spa-view-engine-handling-contextual-information-and-user-authorization"&gt;Data Moving Plug-in SPA View Engine: Handling Contextual Information and User Authorization&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div style="padding-bottom: 1ex; background-color: gray; padding-left: 1ex; padding-right: 1ex; color: black; padding-top: 1ex"&gt; &lt;p&gt;The RTM version of the Data Moving Plug-in comes with a sophisticated SPA view engine. Views are downloaded dynamically from the server when they are needed together with Javascript AMD modules containing all code they need to work properly. &lt;/p&gt; &lt;p&gt;Views are developed as Mvc Partial Views and are then compiled into client side templates. Accordingly, they may use all Data Moving Plug-in &lt;a href="http://www.mvc-controls.com/controls"&gt;controls&lt;/a&gt; and &lt;a href="http://www.mvc-controls.com/features"&gt;features&lt;/a&gt;.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Also the AMD associated with each View may be developed as Partial Views and may take advantage of the Razor syntax to supply dynamic content to the client. Specifically, the developer may use Html extensions to serialize .Net data structures into their equivalent Javascript data structures, thus avoiding the duplication of the same data structures in both .Net and javascript. Moreover, the AMD content may depend on the language selected and on the user logged – in, and in general it may depend on contextual information, since it is created dynamically.&lt;/p&gt; &lt;p&gt;Both Views and their associated AMD are deployed by Asp.Net Mvc&amp;nbsp; Controllers that take care of verifying user authorizations, of minifying the AMD code, and of handling the caching of both Views and AMD.&lt;/p&gt; &lt;h2&gt;Basics&lt;/h2&gt; &lt;p&gt;Views are organized into logical units, in the same way as several classes are organized into dlls (dynamic load libraries). In turn, each logical unit&amp;nbsp; is composed of two &lt;em&gt;deployment&lt;/em&gt; units: a &lt;em&gt;template module&lt;/em&gt; containing all Views of the logical unit compiled into clients templates, and an &lt;em&gt;overall AMD module&lt;/em&gt; containing the Javascript code associated with all Views of the template module in a minified format. Thus, Mvc Controllers, actually deploy &lt;em&gt;template modules&lt;/em&gt; and &lt;em&gt;overall AMD modules&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;The organization of Views and of&amp;nbsp; their associated AMD modules into deployment units increases the modularity of the application and reduces server round trips.&lt;/p&gt; &lt;p&gt;Typically all View related modules are deployed by an unique Controller that has a different action method for each module. In other words each action method is in charge for deploying both the overall&amp;nbsp; AMD and the template module of a single logical unit.&lt;/p&gt; &lt;p&gt;Below a typical action method:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:27c1bbe3-7a26-404b-b001-784fe3475e26" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ActionResult&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Home(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;bool&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; isJs)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; module = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/Main&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (isJs) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.MinifiedJavascriptResult(module+&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; PartialView(module, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;If the&lt;em&gt; isJs&lt;/em&gt;&amp;nbsp; parameter is &lt;em&gt;true&lt;/em&gt; the controller deploys the overall AMD module, otherwise it deploys the template module. The overall AMD module is deployed by the &lt;em&gt;MinifiedJavascripResult&lt;/em&gt; method that takes care of extracting and minifying all javascript contained in the partial View.&lt;/p&gt; &lt;p&gt;In the example above the template module, and the overall AMD module are contained respectively in the partial views &lt;em&gt;Home/Main.csh&lt;/em&gt;tml, and &lt;em&gt;Home/MainJs.cshtml&lt;/em&gt; located under the controller folder. Both files don’t contain the whole code but just the code needed to package all Views and all AMD modules into single deployment units. Typically, the code of each view and AMD is contained in a separate partial view that is called by the &lt;em&gt;Main&lt;/em&gt; or &lt;em&gt;MainJs&lt;/em&gt; partial view.&lt;/p&gt; &lt;p&gt;Below a typical organization of Views and AMD files handled by a controller called &lt;em&gt;TemplatesController&lt;/em&gt;:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.mvc-controls.com/Media/Default/WindowsLiveWriter/DataMovingPluginSPAViewEngine_12D43/SPA%20Views%20AMDs.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="SPA Views AMDs" border="0" alt="SPA Views AMDs" src="http://www.mvc-controls.com/Media/Default/WindowsLiveWriter/DataMovingPluginSPAViewEngine_12D43/SPA%20Views%20AMDs_thumb.png" width="244" height="452"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Each logical unit is contained in a folder with the same name of the unit. All partial views containing code have the same name of their associated Views with a &lt;em&gt;Js&lt;/em&gt; postfix. The &lt;em&gt;Main&lt;/em&gt; and &lt;em&gt;MainJs&lt;/em&gt; partial views of each folder take care of packaging all partial views contained in the folder into the two deployment units called by the controller.&lt;/p&gt; &lt;p&gt;Below a typical MainJs module:&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:87a2d7e4-165f-4381-a79d-37ad1f0b6e48" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 500px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;define(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.IncludeStaticJsModules(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/MenuJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/RegisterJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;                                  &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/LoginJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/LogoutJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/RegistredJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; mvcct.core.withIncludedModules(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (menuF, registerF, loginF, logoutF, registredF) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (vm, viewName) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (viewName == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Menu&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; menuF(vm);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (viewName == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Register&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; registerF(vm);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (viewName == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; loginF(vm);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (viewName == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Logout&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; logoutF(vm);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (viewName == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Registred&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; registredF(vm);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;   &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;It is an AMD that returns a function of two parameters a data item and a view name. This function will be called with the name of the view to render and with the data item that will be bound to that view. This function just selects a function specific for each view that is defined in a separate partial view. The javascript code in the partial view must be included within &amp;lt;script&amp;gt; tags to get a valid Razor syntax. These tags will be removed by the &lt;em&gt;MinifiedJavascriptResult&lt;/em&gt; helper method in the controller.&lt;/p&gt; &lt;p&gt;The partial views containing the view specific javascript code are included statically in the &lt;em&gt;MainJs&lt;/em&gt; partial view with the call to&amp;nbsp; &lt;em&gt;@Html.IncludeStaticJsModules&lt;/em&gt;. After that , the javascript &lt;em&gt;mvcc.core.withIncludedModules&lt;/em&gt; binds the values returned by all view specific modules to the parameters, &lt;em&gt;menuF&lt;/em&gt;, &lt;em&gt;registerF&lt;/em&gt;,…etc.The structure of a typical view specific module will be descibed later on in this post.&lt;/p&gt; &lt;p&gt;Below also a typical &lt;em&gt;Main&lt;/em&gt; partial view: &lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1076ab06-ea12-4726-8f65-d3409cdcc479" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@model &lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;System.&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;String&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;using&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; SPAExample.Models&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@{&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; toRender = Html.DeclareClientTemplates(Model)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;.AddContentPagePartial&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;FatherVirtualReferenceMenuItem&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;gt;( &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/Menu&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Menu&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;.AddContentPagePartial&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;LoginModel&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/Login&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;.AddContentPagePartial&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;LoginModel&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/Logout&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Logout&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;.AddContentPagePartial&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;LoginModel&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/Registred&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Registred&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;.AddContentPagePartial&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Person&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;gt;(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/Register&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Register&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;.AddPartial&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;VirtualReferenceMenuItem&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home/MenuItem&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;MenuItem&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;toRender.Render()&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;It receives as input the module name. In fact the module name is not fixed, but may contain prefixes with the selected language, the user logged in, and other context-dependent information. Thus, in general, a module name has a structure of the type: en-US/john777/Home.&amp;nbsp; The code contained in the view declares the module, adds a template for each view, and finally renders the whole module The rendered content is an Html node containing several client side template inside it. The first argument of each template declaration is the template, while the last argument is the view local name; the view full name is obtained as: &amp;lt;module name&amp;gt;+”_”+&amp;lt;view local name&amp;gt;. In the example above&amp;nbsp; each template is specified with a partial view, so the first argument is just the partial view name. However, templates may be specified also as in-line razor templates. See &lt;a href="http://www.mvc-controls.com/features/templates"&gt;here&lt;/a&gt; fore more details on templates.&lt;/p&gt; &lt;p&gt;The &lt;em&gt;AddContentPagePartial&lt;/em&gt; helper&amp;nbsp; is a simplified way to define Views that cover the role of virtual pages. In fact each virtual page has the following standard structure:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d9316095-4ab5-41d9-82e2-6c8b04a92c36" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;baseViewModel&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; T Content { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; view { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; module { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;bool&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; hasJs { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;It contains the view local name, the module the view is in (without any contextual prefix), a boolean that is &lt;em&gt;true&lt;/em&gt; if the page has associated javascript code. Then it contains a generic content. The &lt;em&gt;AddContentPagePartial&lt;/em&gt; helper specifies a template for just the content of the page.&lt;/p&gt; &lt;p&gt;Below the two routing rules that pass all AMD and template modules requests to the action methods: &lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a764dd02-4345-4476-be67-8cc7f13abb37" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;routes.MapRoute(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;name: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Templates&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;url: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;templates/{action}/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;defaults: &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; { controller = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Templates&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, action = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, isJs =  &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;routes.MapRoute(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;name: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;templatesAMD&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;url: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;templates_amd/{action}.js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;defaults: &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; { controller = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Templates&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, action = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, isJs = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Below the action method that deploys the “People” template module and overall AMD only to logged users:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:461212f0-e22d-46fa-ad7c-02bb881f0511" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ActionResult&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; People(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; user, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;bool&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; isJs, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ticket)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; module = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;People/Main&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SPASecurity&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.ValidateUser(user, ticket)) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;HttpUnauthorizedResult&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (isJs) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.MinifiedJavascriptResult(module + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; PartialView(module, user+&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;/People&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt;It has two more parameters: the user name, and the authentication ticket. In the template module request the authentication ticket is passed in the asp.net authentication cookie, while in the overall AMD request the ticket is inserted in the query string with the format: ?ticket=&amp;lt;auth ticket&amp;gt;, since Javascript file requests typically do not send cookies.&lt;/div&gt; &lt;div style="padding-bottom: 1ex; background-color: gray; padding-left: 1ex; padding-right: 1ex; color: black; padding-top: 1ex"&gt;The SPA&lt;em&gt;Security.ValidateUser&lt;/em&gt; static method verifes the authentication ticket, and returns an &lt;em&gt;HttpUnauthorizedResult&lt;/em&gt; when the verification fails.&lt;/div&gt; &lt;div style="padding-bottom: 1ex; background-color: gray; padding-left: 1ex; padding-right: 1ex; color: black; padding-top: 1ex"&gt;The username is explicitly inserted in the URL&amp;nbsp; so that both template and javascript files may be cached on a user dependent way. In general, context information like the username and the language selected are stacked before the module name in the URL:&lt;/div&gt; &lt;div style="padding-bottom: 1ex; background-color: gray; padding-left: 1ex; padding-right: 1ex; color: black; padding-top: 1ex"&gt;&lt;em&gt;../en-US/john122/People.js?ticket=&amp;lt;auth ticket&amp;gt;, &lt;/em&gt;and&lt;em&gt; …../en-US/john122/People/&lt;/em&gt;.&lt;/div&gt; &lt;div style="padding-bottom: 1ex; background-color: gray; padding-left: 1ex; padding-right: 1ex; color: black; padding-top: 1ex"&gt;URLs are built automatically this way&amp;nbsp; on the client side according to context rules provided by the developer.&amp;nbsp; We will discuss these rules in the next post about the SPA engine.&lt;/div&gt; &lt;div style="padding-bottom: 1ex; background-color: gray; padding-left: 1ex; padding-right: 1ex; color: black; padding-top: 1ex"&gt;The routing rules for all user dependent modules are :  &lt;p&gt;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a27caa20-08b7-4511-8785-8281baaabd0e" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;routes.MapRoute(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;name: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;TemplatesWithUer&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;url: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;templates/{user}/{action}/&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;defaults: &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; { controller = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Templates&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, action = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, isJs = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;false}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;routes.MapRoute(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;name: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;templatesAMDWithUer&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;url: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;templates_amd/{user}/{action}.js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;defaults: &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; { controller = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Templates&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, action = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, isJs = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;Modules are cached by the browser if we add adequate &lt;em&gt;OutputCache&lt;/em&gt; attributes to the action methods that handle the modules. However modules are cached also inside the Html page with a least recently used strategy to improve performance. As a default the framework cache 10 modules, but this value may be changed by calling the javascript method:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d88455ac-2ee3-48ba-99e1-65e2143100c6" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 100px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.cache(&amp;lt;cache size&amp;gt;);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;h2&gt;The View Engine Cycle&lt;/h2&gt; &lt;p&gt;Views are loaded in “placeholders” bound to&amp;nbsp; model properties: each time the a new data item is inserted in the property, a&lt;em&gt; template selection function&lt;/em&gt; selects a new view to use for rendering the new data item. Before rendering starts the data item is manipulated, and possibly filled with new content by the AMD associated with the selected view.&lt;/p&gt; &lt;p&gt;More specifically, the following procedure is triggered each time a new data item &lt;em&gt;vm&lt;/em&gt; is associated to a “placeholder”:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;A template selection function selects the view to render.  &lt;li&gt;If the module the View belongs to has not been downloaded from the server, yet, it is downloaded.  &lt;li&gt;A function &lt;em&gt;func&lt;/em&gt; returned as value from the AMD associated with the view is evaluated on the data item, and on the view name: &lt;em&gt;func(vm, viewName)&lt;/em&gt;.  &lt;li&gt;The result &lt;em&gt;res&lt;/em&gt; returned by the function evaluation is possibly stored in a property of the data item, and is used also in the last step of this procedure.  &lt;li&gt;The selected view (which is a client template) is instantiated , bound to the data item using knockout bindings, and inserted in the “placeholder”.  &lt;li&gt;if &lt;em&gt;res&lt;/em&gt; contains a property called &lt;em&gt;afterRender&lt;/em&gt;, it is assumed to be a function that is evaluated passing it the array of html nodes created by the view instantiation, and the data item &lt;em&gt;vm&lt;/em&gt;.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Thus, the developer may modify &lt;em&gt;vm&lt;/em&gt; before its rendering with &lt;em&gt;func&lt;/em&gt; and immediately after its rendering with the &lt;em&gt;afterRender&lt;/em&gt; function. Typically, &lt;em&gt;func&lt;/em&gt; fills &lt;em&gt;vm&lt;/em&gt; with javascript content while &lt;em&gt;afterRender&lt;/em&gt; applies jquery plugins to the rendered content, and specifies options of &lt;a href="http://www.mvc-controls.com/features/server-updates"&gt;updatesManagers&lt;/a&gt; and &lt;a href="http://www.mvc-controls.com/features/queries"&gt;retrievalManagers&lt;/a&gt; possibly created during the view rendering. &lt;/p&gt; &lt;p&gt;Typically, data items, representing “virtual pages” are initially empty, and contain just the page complete name (module name + view name). The whole page content is put in place by &lt;em&gt;func&lt;/em&gt;. The function &lt;em&gt;func&lt;/em&gt; is the same for each module and it is the function returned by each &lt;em&gt;MainJs&lt;/em&gt; partial view, we discussed before in this post. It just dispatches the call to view specific functions. Below a view specific javascript module that prepares a menu virtual page:&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0e0e82bc-c516-43bd-8800-06e3ea8e3ced" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 500px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; menuItems = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;List&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;BaseVirtualReferenceMenuItem&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; menuItem = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;VirtualReferenceMenuItem&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;virtualReference&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;() { module = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, view = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, }, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.LinkToLoginText, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.LoginTitle);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;menuItems.Add(menuItem);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;menuItem = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;VirtualReferenceMenuItem&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;virtualReference&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;() { module = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, view = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Register&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, }, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.LinkToRegisterText, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.RegisterTitle);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;menuItems.Add(menuItem);  &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;menuItem = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;VirtualReferenceMenuItem&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;virtualReference&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;() { module = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;People&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, view = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;List&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, }, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.LinkToHumanResourcesListText, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.HumanResourcesListTitle);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;menuItems.Add(menuItem); &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; mainMenu = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;FatherVirtualReferenceMenuItem&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;Children = menuItems&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;   &lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.JavaScriptDefine(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;mainMenu&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,  mainMenu) &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.core.moduleResult(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (vm) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!vm._initialized) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm._initialized = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm.Content = ko.mapping.fromJS(mainMenu);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm._title = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.HomeTitle&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;})();  &lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;The data structure containing all menu information is built in .Net with the help of the &lt;em&gt;virtualReference&lt;/em&gt; class that defines virtual links to virtual pages. Text content is taken from a resource file, so it may depend on the selected language. The &lt;em&gt;VirtualPageMenuItem&lt;/em&gt; class is not part of the Data Moving Plug-in, but is specific of the example.&lt;/p&gt; &lt;p&gt;The .Net data structure is serialized in javascript by the &lt;em&gt;JavascriptDefine&lt;/em&gt; helper that defines a javascript variable named &lt;em&gt;mainMenu&lt;/em&gt; and fills it with the serialized data structure.&lt;/p&gt; &lt;p&gt;The &lt;em&gt;mvcct.core.moduleResult&lt;/em&gt; javascript funtion returns the module result to the calling &lt;em&gt;MainJs&lt;/em&gt; AMD. The returned value is the function that will be applied to the data item &lt;em&gt;vm&lt;/em&gt; in case the view required is a “Menu” view. If &lt;em&gt;vm&lt;/em&gt; has not been already initialized this function fills the &lt;em&gt;Content&lt;/em&gt; property of the virtual page with the data structure describing the whole menu.&lt;/p&gt; &lt;p&gt;Below a javascript module that uses an &lt;em&gt;afterRender&lt;/em&gt; function to apply a jQuery plugin to the submit button:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2a475abd-5152-481b-abb2-d296db140172" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 500px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;   &lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.JavaScriptDefine(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;personForm&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Person&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;() ) &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; afterRender = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (nodes, vm) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; root = $(mvcct.core.filterHtml(nodes));&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (root.length == 0) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; prefix = root.attr(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;data-helper-prefix&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;$(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;#&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; + prefix + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;_btnSubmit&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;).button().click(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; form = $(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;).closest(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;form&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (form.validate().form()) vm.updater.update(form);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.core.moduleResult(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (vm) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!vm._initialized) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;vm._initialized = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; {afterRender: afterRender };&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;})();  &lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;It is worth to point out how the button is located in the page. We can’t use a Css class to locate the button since this way we would risk to re-apply the jquery plug-in also to other buttons contained in other instances of the same view that have already been rendered in the Html page. A &lt;em&gt;.find&lt;/em&gt; applied only to the newly created content might be too inefficient since it would not use CSS inedexes of the Html page.&amp;nbsp; Thus, the best solution is using ids and Css classes that are specific to the instance of the view. In our case we prefix the button id with an unique identifiers, different for each view instance, with the &lt;em&gt;PrefixedId&lt;/em&gt; helper:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a5a243a8-42fd-4728-ae6f-0608eb2c61e3" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;input&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;id&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.PrefixedId(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;btnSubmit&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;button&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;value&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Submit&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;button&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The same prefix is added in the data-helper-prefix html5 attribute of the root node of the template:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:40a65b69-3622-4403-ad0f-698d2acd402c" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;JQueryUICssClasses&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.ContentContainer+&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot; main-page&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;data-helper-prefix&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.PrefixedId(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;This way the javascript module may read the prefix that uniquely identifies the page instance with:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:efb7088a-01ff-4928-88c7-f3395d7cfd9f" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; prefix = root.attr(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;data-helper-prefix&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;and it may use it to locate all html content in the view instance. The root html node is computed by filtering out all not-Html nodes from the array of all rendered nodes with the helper function: &lt;em&gt;mvcct.core.filterHtml&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;The content of each AMD, may depend on parameters like the selected language, or the user logged in, but it can’t depend on the specific database state since, for performance reasons,&amp;nbsp; AMD module must be cached by the browser. Therefore, data coming from the database can’t be added to&amp;nbsp; &lt;em&gt;vm&lt;/em&gt; by &lt;em&gt;func&lt;/em&gt;, that is part of an AMD, but must be required to the server with a subsequent ajax call placed in the &lt;em&gt;afterRender&lt;/em&gt; function or by instructing a &lt;em&gt;retrievalManager&lt;/em&gt; to fetch data from the server as soon as it has been created. &lt;/p&gt; &lt;p&gt;Below a &lt;em&gt;retrievalManager&lt;/em&gt; instructed to fetch data from the server immediately after it has been created:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0b0e0540-26ef-43a3-911f-b78bee7be942" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.StartAjaxPostRetrievalManager(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;@._utilities.humanResourcesRM&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;1, actionUrl: Url.Action(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;JsonQuery&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;HumanResources&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;))&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;It is enough to set to &lt;em&gt;true&lt;/em&gt; the first parameter passed to the &lt;em&gt;retrievalManager&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;The javascript module associated to the view of the &lt;em&gt;retrievalManager&lt;/em&gt; above, specifies some options for the &lt;em&gt;retrievalManager&lt;/em&gt; and for an &lt;em&gt;updatesManager&lt;/em&gt; rendered in the view in its &lt;em&gt;afterRender&lt;/em&gt;:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c52200a8-b89b-430d-bf64-7f1ae5214cc1" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 500px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;   &lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.JavaScriptDefine(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;viewModel&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,  &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;HumanResourcesViewModel&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;()) &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; afterRender(nodes, vm) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;vm.updater.options({&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;onUpdateComplete: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;$.unblockUI();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;},&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;htmlStatusMessages: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (statusCode, statusText) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (statusCode == 401) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Unauthorized&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; statusText;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;},&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;updatingCallback: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;$.blockUI();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;vm._utilities.humanResourcesRM.options({&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;htmlStatusMessages: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (statusCode, statusText) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (statusCode == 401) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Unauthorized&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; statusText;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.core.moduleResult(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (vm) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (!vm._initialized) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; { afterRender: afterRender };&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;})();  &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The options passed specify custom error messages in case of unauthorized access to the server methods (status code 401), and apply screen blocking during the communication with the server.&lt;/p&gt; &lt;h2&gt;Defining the View Placeholders&lt;/h2&gt; &lt;p&gt;Views are loaded into View placeholder, that are bound to model properties. Root placeholders are inserted in the host Html page and each view may,&amp;nbsp; in turn, contain nested view placeholders. Views inserted in root placeholders play the role of virtual pages, while nested views play the role of “widgets”. A physical Html host page may contain several virtual pages, but most of SPA contain just a single root view placeholder that is connected with the &lt;em&gt;back&lt;/em&gt; and &lt;em&gt;forward&lt;/em&gt; browser buttons to simulate the behavior of a standard Html page.&lt;/p&gt; &lt;p&gt;Root placeholder are defined with the &lt;em&gt;ClientIteratorFor&lt;/em&gt; helper extension. Below an example of usage:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:59354f2c-0c87-45de-bfed-c2a7d4d4623c" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;page-container&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;h.ClientTreeIteratorFor(m =&amp;gt; m.CurrentPage, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;function(x){ $(mvcct.core.filterHtml(x)).fadeOut(0).fadeIn(500);}&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;function(x, y, i, f){$.when($(mvcct.core.filterHtml(x)).fadeOut(500)).always(f);}&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The first parameter is the property that will be bound to the view placeholder. Each time a new data item is inserted in this property the view engine cycle is run to load a new view. In SPA applications the second parameter is always null, while the third and fourth parameters specify respectively a before render and an after render functions. They are used to implement transition animations. In the example above the before render function runs a fade-out animation, while the after render function specifies a fade-in animation. When the before render animation completes it MUST call the function &lt;em&gt;f&lt;/em&gt; passed as fourth parameter to inform the view engine that it can remove the old view and can insert the new one.&lt;/p&gt; &lt;p&gt;Placeholders for nested views are specified with &lt;em&gt;RecurIterationOnSingle&lt;/em&gt; and &lt;em&gt;RecurIterationOn&lt;/em&gt; html extensions. The first one adds a single view instance and may be bound to a property containing a single data item, while the second one adds several views, one for each data item contained in the &lt;em&gt;IEnumerable&lt;/em&gt; it is bound to. Below a &lt;em&gt;RecurIterationOnSingle&lt;/em&gt; renders a widget containing a page header and a &lt;em&gt;RecurIterationOn&lt;/em&gt; helper renders all menu item of a menu page:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:05703a84-c1f3-498c-bb27-c189f727e516" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;JQueryUICssClasses&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.ContentContainer+&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot; main-page&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;h1&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;JQueryUICssClasses&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.HeaderContainer+&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot; main-menu-title&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.HomeTitle&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;h1&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.RecurIterationOnSingle(m =&amp;gt; m.Header,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;wrapper: &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ExternalContainerType&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.div, wrapperAttributes: &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; {data_spa_widget=&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Basic.NavigationHeader.js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, @class=&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;header-links&amp;quot;}&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.RecurIterationOn(m =&amp;gt; m.Children,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;wrapper: &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ExternalContainerType&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.nav, wrapperAttributes: &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; {data_spa_widget=&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home.MenuItem&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, @class=&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;main-menu&amp;quot;}&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Their first parameter is the property the placeholder will be bound to, while the &lt;em&gt;wrapper&lt;/em&gt; and &lt;em&gt;wrapperAttributes&lt;/em&gt; optional parameters specify respectively an html node that will enclose the dynamic content and its Html attributes. The &lt;em&gt;data-spa-widget&lt;/em&gt; html5 attribute specifies witch view to render. More details on the use of this attribute are contained in the next section.&lt;/p&gt; &lt;p&gt;Also the &lt;em&gt;RecurIterationOnSingle&lt;/em&gt; and &lt;em&gt;RecurIterationOn&lt;/em&gt; html extension allow before render and after render animations useful to define transition.&lt;/p&gt; &lt;h2&gt;Virtual Pages and Default Template Selection Function&lt;/h2&gt; &lt;p&gt;The view to load is decided by a template selection function. The default template selection function is able to select the view to load just for &lt;em&gt;virtual pages&lt;/em&gt; and for &lt;em&gt;widgets&lt;/em&gt;. Normally, this is enough, but the developer has also the option to specify a custom template selection function to be used for all nested views of a module, as first parameter of the Render function of the module definition:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7f0094c0-ecfe-4c59-a147-76ba13061c02" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@{&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; toRender = Html.DeclareClientTemplates(Model)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;toRender.Render(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;$data.myCustomTemplateSelection&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;$data&lt;/em&gt; bindings variable specifies that the function is contained in the current view model. We may use also &lt;em&gt;$parent&lt;/em&gt;, etc. For more details see &lt;a href="http://knockoutjs.com/documentation/binding-context.html"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Virtual pages are data items that works as empty containers and that specify the view they “need” through their &lt;em&gt;view&lt;/em&gt;, &lt;em&gt;module&lt;/em&gt;, and &lt;em&gt;hasJs&lt;/em&gt; properties, so the default template selection needs just to read these properties. The selected AMD module fill the Content property of the empty page with content specific for the selected view and transforms the empty page into a complete working page.&lt;/p&gt; &lt;p&gt;Nested views (views that are not virtual pages) may be selected by the default template selection functions by means of the &lt;em&gt;data-spa-widget&lt;/em&gt; html5 attribute that may be placed in the wrapper Html node that encloses the view placeholder. Its format is: &amp;lt;module&amp;gt;.&amp;lt;view&amp;gt;[.js]. The js suffix specifies that the module has an associated AMD module.&lt;/p&gt; &lt;p&gt;Pages are handled by &lt;em&gt;mvcct.ko.dynamicTemplates.pageStore&lt;/em&gt; instances. When the application starts a default &lt;em&gt;pageStore&lt;/em&gt; instance is created&amp;nbsp; and inserted in the &lt;em&gt;mvcct.ko.dynamicTemplates.defaultPageStore&lt;/em&gt; variable. The developer needs to create other &lt;em&gt;pageStore&lt;/em&gt; instances only if the host page contains several page placeholders.&lt;/p&gt; &lt;p&gt;Pages are created by passing a &lt;em&gt;virtualReference&lt;/em&gt; object to the &lt;em&gt;get&lt;/em&gt; method of a &lt;em&gt;pageStore&lt;/em&gt; instance. Once we receive the requested virtual page from the get method we may place it in a property associated with a virtual page placeholder. This trigger automatically the view loading procedure. &lt;/p&gt; &lt;p&gt;Below the first page loading that bootstraps an SPA:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:55c79a94-7846-4e6c-9272-e889a18678a3" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 200px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;applicationModel.CurrentPage(mvcct.ko.dynamicTemplates.defaultPageStore.get(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; mvcct.ko.dynamicTemplates.virtualReference(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Menu&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)));&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;If the &lt;em&gt;stored&lt;/em&gt; property of the &lt;em&gt;virtualReference&lt;/em&gt; is &lt;em&gt;true&lt;/em&gt; (its default) the virtual page is stored in the page store after its creation, while if the &lt;em&gt;stored&lt;/em&gt; property is &lt;em&gt;true&lt;/em&gt; (its default) an already stored virtual page with the same full name will be returned, if available in the page store. The &lt;em&gt;virtualReference&lt;/em&gt; may specify also a &lt;em&gt;role&lt;/em&gt; string property. In this case a stored page is returned only if the role specified when it was created matches the role of the &lt;em&gt;virtualReference&lt;/em&gt; passed to the get method. &lt;/p&gt; &lt;p&gt;After the SPA bootstrap a new page may be loaded passing a &lt;em&gt;virtualReference&lt;/em&gt; directly to the &lt;em&gt;goTo&lt;/em&gt; method of current page. If no second argument is passed the page is retrieved from the default page store, otherwise the second argument must be the page store to use. Most of the times, we don’t call directly the &lt;em&gt;goTo&lt;/em&gt; method but use the &lt;em&gt;VirtualLink&lt;/em&gt; and &lt;em&gt;VirtualLinkFor&lt;/em&gt; html extensions that do this job for us:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e72a6aae-c207-469e-9f98-96b7c4b3f6f9" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 100px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.VirtualLinkFor(m =&amp;gt; m.Text, m =&amp;gt; m.Link, title: m =&amp;gt; m.Title)&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Where the &lt;em&gt;Link&lt;/em&gt; property must contain an instance of the &lt;em&gt;virtualReference&lt;/em&gt; class.&lt;/p&gt; &lt;p&gt;The main purpose of the page store is to keep the state of each page, so that when the user returns on the same page he finds the page exactly in the same state he left it. This ensures a better user experience, and makes the SPA similar to a native windows application.&lt;/p&gt; &lt;p&gt;A call to the &lt;em&gt;enablePushState&lt;/em&gt; method of a &lt;em&gt;pageStore&lt;/em&gt; instance connects it to the browser history, so the user may navigate among the virtual pages with the &lt;em&gt;back&lt;/em&gt; and &lt;em&gt;forward&lt;/em&gt; browser buttons. If the browser doesn’t support &lt;em&gt;pushState&lt;/em&gt;, the view engine reverts automatically to a software simulation.&lt;/p&gt; &lt;h2&gt;Static Modules&lt;/h2&gt; &lt;p&gt;Some modules might be loaded immediately when the SPA starts. For instance it is convenient that widgets used by all pages, such as page headers and footers&amp;nbsp; be loaded as soon as the SPA starts and kept in the page for the whole lifetime of the page. The error page that is shown in case of module loading errors MUST be loaded statically when the SPA starts to ensure that it is always available in case of network problems.&lt;/p&gt; &lt;p&gt;Loading modules statically is straightforward. The AMD module is required with a standard javascript &amp;lt;script&amp;gt; tag:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2c592444-137f-45dd-b673-bfebda63ae8c" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 200px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;src&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Content(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;~/templates_amd/Basic.js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;However, in this case the define instruction contained in the module MUST specify explicitly the module name:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:922b6c61-3e6b-44da-a4ac-3aec7f4d2e98" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;define(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Basic&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.IncludeStaticJsModules(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Basic/NavigationHeaderJs&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; mvcct.core.withIncludedModules(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (navigationHeaderF) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (vm, viewName) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (vm &amp;amp;&amp;amp; viewName == &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;NavigationHeader&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; navigationHeaderF(vm);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;});  &lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The template module, instead, is defined inside the host page in exactly the same way it is defined in a &lt;em&gt;Main.cshtml&lt;/em&gt; file:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9c3930e5-33d5-4a3a-83bc-9a37f4f89b36" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 200px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@{&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; errorTemplates = Html.DeclareClientTemplates(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Basic&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;errorTemplates.Render()&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h2&gt;The Host Page&lt;/h2&gt; &lt;p&gt;The host page must specify the following configuration information:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Possible options of the AMD loader. The Data Moving Plug-in officially supports &lt;em&gt;&lt;a href="http://requirejs.org/docs/api.html"&gt;require.js&lt;/a&gt;&lt;/em&gt;, but other AMD loaders with the same interface should work as well.  &lt;li&gt;The base url where to download the template modules and the base url where to download the associated AMD modules  &lt;li&gt;Loader callbacks that block/unblock the screen during the module loading, and that specify which view to show in case of load errors.  &lt;li&gt;The template modules cache size, if different from the 10 default.  &lt;li&gt;Some &lt;em&gt;pageStore&lt;/em&gt; configuration (typically just if the page store must be connected to the browser history)&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Typically all this information is inserted in the page header as shown in the example below:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6eea6c49-cd7e-4a31-b709-bfd71612ea65" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 500px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@section Header{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;link&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;href&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;~/Content/Site.css&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;rel&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;stylesheet&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;src&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Content(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;~/Scripts/jquery.blockUI.min.js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; require = {&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;baseUrl: &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Content(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;~/Scripts/Modules&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;waitSeconds: 10&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Html.JavaScriptDefine(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;viewModel&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,  &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;PageError&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;())  &lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.callBacks({&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;onLoad: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () { $.blockUI(); },&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;onLoadEnd: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () { $.unblockUI(); },&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;onLoadFailed: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (module, nodes, data) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;data._errorPage = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Basic_defaultError&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;data.Content = ko.mapping.fromJS(viewModel); &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;data.Content.ErrorMessage(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;SiteResources&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.PageLoadError&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; + module);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;},&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.defaultPageStore.enablePushState(2);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.cache(5);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.service(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;          &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Content(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;~/templates&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;/&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;          &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Content(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;~/templates_amd&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; + &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;#39;/&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;); &lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;src&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;~/Scripts/Modules/contextRules.js&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;src&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;~/Scripts/require.js&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;src&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Content(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;~/templates_amd/Basic.js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Then the host page body must get &lt;a href="http://www.mvc-controls.com/features/client-server"&gt;a client viewmodel aware Html helper&lt;/a&gt;:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7591d52a-aa3e-4e56-8d07-da1451f4565c" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 100px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@{&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; h = Html.SendToClient(m =&amp;gt; m, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;applicationModel&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;page-container&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;and must use it to render the root view placeholder:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f1c880ea-a2ed-45d3-8390-9820c400e758" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 500px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;page-container&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;h.ClientTreeIteratorFor(m =&amp;gt; m.CurrentPage, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;function(x){ $(mvcct.core.filterHtml(x)).fadeOut(0).fadeIn(500);}&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;function(x, y, i, f){$.when($(mvcct.core.filterHtml(x)).fadeOut(500)).always(f);}&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Finally the page host should contain a javascript script tag with the code that bootstraps the SPA by creating its first virtual page, and if the application uses authorization, the code that bootstraps the SPA authorization system:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b8cd4414-9019-46e9-a542-ecc46045b53c" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;$(document).ready(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;mvcct.ko.dynamicTemplates.enableAuthorizationManager(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Action(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;CurrentUser&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffff00;color:#000000"&gt;@&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;Url.Action(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Logout&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;applicationModel.CurrentPage&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000"&gt;applicationModel.CurrentPage(mvcct.ko.dynamicTemplates.defaultPageStore.get(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; mvcct.ko.dynamicTemplates.virtualReference(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Menu&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;)));&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;That’s all for now! In the next post we will see the SPA engine authorization framework, and how the SPA framework handles context-dependent information such as the user logged in and the selected culture. A video showing the Data Moving Plug-in SPA View Engine is available &lt;a href="http://www.mvc-controls.com/features/spa-framework"&gt;here&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Francesco&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;</description><pubDate>Sun, 01 Sep 2013 21:34:58 GMT</pubDate><guid isPermaLink="true">http://datamoving.mvc-controls.com:80/blog/data-moving-plug-in-spa-view-engine</guid></item><item><title>The Code of all Data Moving Plug-in Examples is Available on Codeplex</title><link>http://datamoving.mvc-controls.com:80/blog/the-code-of-all-data-moving-plug-in-examples-is-available-on-codeplex</link><description>&lt;p&gt;The code of all Data Moving Plug-in examples shown in all previous videos and tutorials is available on the &lt;a href="https://datamovingexamples.codeplex.com/" title="Data Moving Plug-in Examples"&gt;Data Moving Plug-in Examples&lt;/a&gt; Codeplex site. All examples require the installation of the Data Moving Plug-in, so at moment only the ones that received an evaluation or complimentary copy of the Data Moving Plug-in may run them. However, it is interesting in any case to inspect the full code for anyone who already read a tutorial or watched a video &amp;nbsp;about the Data Moving Plug-in.&lt;/p&gt;</description><pubDate>Wed, 19 Jun 2013 07:00:00 GMT</pubDate><guid isPermaLink="true">http://datamoving.mvc-controls.com:80/blog/the-code-of-all-data-moving-plug-in-examples-is-available-on-codeplex</guid></item></channel></rss>