Click here to Skip to main content
13,148,503 members (67,090 online)
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 26 Jan 2014

Convert a MVC4 Application to a "Cool Towel" Single Page Application (SPA)

Rate this:
Please Sign up or sign in to vote.
Example project template for a "Cool Towel" SPA to be filled with a MVC4 application HTML5 and JavaScript code in order to convert
Screenshot running out-of-the-box Cool Towel SPA project template


This tip is about making website navigation just as fast as a desktop application and with the same look and feel, for example in an ASP.NET MVC4 internet application by converting it to a "Cool Towel" Single Page Application (SPA). This is done by putting the HTML5 code of each internet application page in the appropriate places of the SPA project template, also incorporating in this solution the corresponding JavaScript and controller code. A Cool Towel: You do not go to the SPA without one!


A SPA, also known as single-page interface (SPI), is a web application or web site that fits on a single web page with the goal of providing a more fluid user experience akin to a desktop application. In a SPA, either all necessary code – HTML, JavaScript, and CSS – is retrieved with a single page load. The page does not reload at any point in the process, nor does control transfer to another page.

Using the Code

Open the SPA_Project_Template_01 solution in Visual Studio 2012 or later. Copy / paste the HTML5 code of your pages in the "XXXX HTML5 Here" placeholders in the Index.cshtml, add the JavaScript files, add the CSS files and controller files also. Be sure that all the JavaScript and CSS files are referenced in the Index.cshtml

Out-of-the-box the navigation buttons have the click event Knockout data binded (HTML5 code):

<div class="float-right">
        <ul id="menu1">
                <input type="button" value="Home" data-bind="click: $root.divHome" /></li>
                <input type="button" value="Manual" data-bind="click: $root.divManual" /></li>
                <input type="button" value="Blog" data-bind="click: $root.divBlog" /></li>
                <input type="button" value="Balance" data-bind="click: $root.divBalance" /></li>
                <input type="button" value="Budget" data-bind="click: $root.divBudget" /></li>
                <input type="button" value="About" data-bind="click: $root.divAbout" /></li>
                <input type="button" value="Contact" data-bind="click: $root.divContact" /></li>

Out-of-the-box these click events trigger JQuery opening on collapsing of the placeholder <div>s, like (JavaScript code):

function appViewModel() {

    var self = this;

    self.divHome = function () {

Points of Interest

Navigation of the demo website that took about 2 seconds according to the PageSpeed Chrome pluggin now is like instantaneous in a view microseconds. Moreover the bootstrap time of the entire SPA Index.cshtml, when application pool and website IIS are alive, has only doubled, from about 2 to 4 seconds, compared to loading the HOME page only of the MVC4 Internet Application.


  • 25th January, 2014: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Johan G. van der Galien
Web Developer SATOCONOR
Netherlands Netherlands
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...

Comments and Discussions

QuestionMicrosoft: Change for the sake of change Pin
Johan G. van der Galien29-Jan-14 17:07
professionalJohan G. van der Galien29-Jan-14 17:07 
QuestionMeant for simple websites, for the youth: The new generation developers Pin
Johan G. van der Galien29-Jan-14 5:43
professionalJohan G. van der Galien29-Jan-14 5:43 
Question[My vote of one] Total Fail Pin
alec.whittington27-Jan-14 4:58
memberalec.whittington27-Jan-14 4:58 
Question[My vote of 1] mmmm not sure Pin
Sacha Barber26-Jan-14 21:45
mvpSacha Barber26-Jan-14 21:45 
AnswerRe: [My vote of 1] mmmm not sure Pin
Johan G. van der Galien29-Jan-14 5:17
professionalJohan G. van der Galien29-Jan-14 5:17 
AnswerRe: [My vote of 1] mmmm not sure Pin
Johan G. van der Galien29-Jan-14 5:30
professionalJohan G. van der Galien29-Jan-14 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170924.2 | Last Updated 26 Jan 2014
Article Copyright 2014 by Johan G. van der Galien
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid