Chapter 3. Introduction to Knockout.js

Knockout.js is an open source JavaScript library that allows you to create dynamic and rich web applications. It is built with the Model-View-ViewModel (MVVM) pattern. Knockout makes it really simple to implement a complex user interface that responds to user interactions.

I like Knockout because it is one of the most lightweight JavaScript libraries available today. It also doesn’t try to be an all-in-one framework. It serves a single purpose:  data binding your ViewModel to your user interface.

Implementing Knockout involves three distinct things: a view that contains HTML and CSS elements that get data-bound to it, a ViewModel that contains the data to bind to the view, and telling Knockout to perform the data binding to the view with the ViewModel.

Installing Knockout.js

Knockout.js can be installed in one of two ways:

  • Downloading the latest version from the Knockout downloads page.
  • Installing Knockout via the NuGet Package Manager.

My preference is the NuGet Package Manager because it makes it easier to update to a new version if/when a newer version is available.

The NuGet Package Manager is integrated directly into Visual Studio and allows developers to easily install (or create their own) packages to install and manage third-party dependencies.

To install Knockout, perform the following operations:

  1. Click the Tools menu.
  2. Click the NuGet Package Manager submenu.
  3. Click the NuGet Packages for Solution menu.
  4. On the left, click Online ...

Get ASP.NET MVC 5 with Bootstrap and Knockout.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.