Building SPA with Angular and MVC 5

Hi Friends, It gives me immense pleasure to share the 1st chapter of this book. 1

Chapter 1: Getting Started

 WHAT DO you find in this CHAPTER?


  • Introduction
  • What is SPA
  • Technologies used to build SPA
  • Glimpse of Movie Review App
  • Summary


Hi my name is Rahul Sahay and I am going to introduce this whole new story of building Single Page Application right from the scratch. Here, in this context I am going to talk about bunch of different client/server side technologies and demonstrate how these small pieces marry together and creates a robust End to End application. So, without wasting time let’s get started.


What is SPA:-

Single Page App is all about user experience. People will love your app if you give them nice user experience which not only fits nicely in your laptop or desktop rather it goes nicely with multitude of devices like tabs, phones etc without breaking any single functionality. As shown in the below diagram, these are basic requirements for building any SPA.



  • Reliability: – People know that it’s reliable and it’s going to work. This kind of reliability only comes with positive experience.
  • Responsiveness: – Responsiveness means it’s going to work quickly for them. Quick is the key thing which any user expect to have in the app which he is using.
  • Reach: – Reach is often substituted with mobility. Mobility is again one of the key ingredient which every user is looking for. They always want to have the data handy with irrespective of what device they are on.
  • Available: – This thing is really important when it comes to the point at working offline. So, delivering a good user experience is must while building SPA.

So, in a nutshell a Single Page App is web application which fits in a single page providing a fluid UX by loading all the necessary data in a single load.”   Now, apart from this there are many other attributes linked to SPA. They are:-

  • Maintain History: – When you flip between pages, it maintains your history in the same order how you visited them. Actually, it’s not going on different pages rather its loading different information’s on the same page. But, it looks to user that it’s presenting different pages to them.


  • Persisting Information: – Persisting information is also very important aspect of the SPA. It doesn’t mean that you need to save each and every thing at cache but you can store important things in the cache to improve the performance.


  • Mostly loaded on Page Load: – Mostly loaded on the page load means majority of information user required to use gets loaded initially itself to avoid roundtrip back to the server.


  • Dependent Elements: – As and when user requires to access different features of the application, app will go and download for the user.


Technologies used to build SPA:-

Movie Review app is built using tons of different client side and server side technologies. Some of these I have listed below:- Client Side Technologies:-

  • HTML 5 & CSS
  • Modernizer & LESS
  • Media Queries
  • Responsive Design
  • Angular JS
  • Toastr JS
  • JQuery
  • QUnit JS
  • JQuery.MockJSON
  • Change Tracking
  • And many out of the box things

Server Side Technologies:-

  • SQL Server
  • Entity Framework – Code First Approach
  • Repository Pattern
  • Unit of Work Pattern
  • Web API
  • NuGet
  • Ninject IOC
  • POCO Models

Glimpse of Movie Review App:-

I think it would be good idea you to show you finished app before directly jump in creating the same. Here is the URL where I have hosted my app. Now, when you click on this, you will land on the below shown page. 170th 171th Above shown screen shot is the home page of the app. Now, when you click on the Movies link, it will take you to the below shown page. 172nd Once, page gets loaded, little toast message at the bottom right of the screen pops up saying Movies Fetched Successfully. Now, from this screen you can do all the CRUD Operation. Here the very 1st link is Add Movie, which will give user flexibility to go ahead and add any new movie as shown below. 173rd Now, let’s suppose if we try to post the Form as it is blank, then it won’t allow, because above fields are required as marked by its CSS color and star mark as well. Now, once I enter any information, different validation will get triggered 174th Even at this moment I cannot submit the form as the form is invalid. Once, I modify and enter valid details, then form error messages and its error color (Red) will disappear. 175th Now, at this instant I can go ahead and submit the movie. Once I click submit button; one toast message will appear saying Data Saved Successfully and will get redirected back to movies link. 176th 177th Next is the Edit link corresponding to the movie. When you click on this, it will present the below screen for editing the same. 178th Here, also each and every validation will be there, what we have seen during creation. However, you can go ahead and edit anything over here, let’s say I change the year to 2002 and update. 179th Once I update the movie it will save the same in database and then get redirected to Movies link as shown below. 180th However, let me change the same back to the original one as it’s not correct. Similarly, you can go ahead and delete the movie from the Edit link as well. Next to Edit link, there is link for Reviews as well. From this link you can go ahead and add new review as shown below. 181th Here, when I click on Add New Review, it will take me to the below form. 182nd Above form has also got different set of validations as shown below. 183rd Once done all the corrections, it will be like this 184th After successful, submission, it will redirect back to the movies link. 185th After adding Review, position of newly added movie moves up in the list as behind the scene order by clause is working on total no of reviews. Now, when I click on the Reviews link again, it will show me the review which I have added. 186th Here, corresponding to the Review, new Edit link also got enabled for editing or deleting the Review. This also works same what I explained above for Movie. About App link lists all the details of the application like what technologies used what tools you need, where to download the code etc…. 187th 188th 189th I have also used QUnit Library to test my Web APIs. Below is the glimpse for the same. 191th When you click on any individual test, it will present you the detailed results as shown below in the screen shot. 192nd And if there is anything wrong with any end points, let’s suppose that doesn’t exist; easiest way to break the test, then it will be like 216th You can also verify these APIs like shown below 203rd Similarly different endpoints can be tested. Apart from Web API tests. I have also used Jasmine to test my Angular code. You will also learn how to test client side JavaScript code with Visual Studio. Here, I have used Chutzpah to integrate JavaScript Tests with Visual Studio. Below is the glimpse for the same. 194th Now, when I check code coverage results for my tests, Chutzpah will open a new window in browser with the code coverage results for the client side as shown below in the screen shot. 193rd The ones which are highlighted in red are the ones which are not covered 100%, so when I click on any of this link, it will open the code in browser and show what is covered and what is not 196th

Glimpse of Movie Review Solution:-

Let me go ahead and show you the solution structure of finished app. Below in the screen shot, I have 5 different projects. Each is having its on dependency and responsibility. 197th Here, the highlighted one is the web project which is dependent on other infrastructure projects Data, Contracts and Model. Data project is the place where in you maintain initial seed data, Entity Framework DBContext and many more things involve direct interfacing down the layer with database. Data Contract is the place where in you manage your repositories and apply Unit of Work Pattern on repositories like movies and moviereviews. Model is the place where you will be having your POCOs (Plain Old CLR Objects). This is the place where in you are maintaining all properties attributed to the tables. Below is the glimpse of all projects in its expanded form. 198th 199th 200th 201th 202nd

App Speed:-

In the below screen you can find, that almost at every parameter, angular app is lightning fast.



In this section, we have seen the bits and bytes of the Single Page Application which we are going to make using tons of client/server side framework. We have also seen the glimpse of app and solution. In the next section, we’ll begin the learning by creating the application right from the scratch. I would recommend you to download the app from github URL shown below to help you while building . I hope you have enjoyed the glimpse. More more info you can have the same from the below mentioned link.

Rahul Sahay
Happy Coding

16,948 total views, 9 views today

Leave a Reply