Book Image

Getting Started with Knockout.js for .NET Developers

By : Andrey Ankshin
Book Image

Getting Started with Knockout.js for .NET Developers

By: Andrey Ankshin

Overview of this book

Table of Contents (14 chapters)
Getting Started with Knockout.js for .NET Developers
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Development of a big web application is a hard task. Because of this, people try to use different useful and flexible approaches to build the architecture of their applications. One such approach is Knockout.js. It is a JavaScript library that provides you with a sophisticated way to communicate between your UI and the underlying data model to create rich web user interfaces based on the Model-View-ViewModel (MVVM) pattern. Knockout.js provides a simple two-way data binding mechanism between your data model and UI, which means that any change to your data model is automatically reflected in the UI and vice versa. Instead of using pure Knockout.js, you can use Knockout MVC. It is a library for ASP.NET MVC, which is a wrapper for Knockout.js that helps to move the entire business logic to the server side; the complete JavaScript code necessary on the client side will be generated.

This book will provide you with the skills you need to successfully create a Knockout.js-based application of varying complexity, from a simple Knockout.js web page in pure JavaScript to a complex ASP.NET web application. You will learn how you can use the MVVM design pattern, including the dependency tracking system and observable properties for creation of powerful sites with a clear separation of model, logic, and view layers.

What this book covers

Chapter 1, Introduction to Knockout.js, teaches basic Knockout.js concepts (overview), such as MVVM design pattern (including the creation of Model, ViewModel, and View), binding, observables, and subscribe machinery. Also, we'll consider an installation process for the library.

Chapter 2, Creating a Simple Knockout.js Application, covers how to use advanced Knockout.js features, such as working with observables arrays, special bindings, and computed observables.

Chapter 3, Integrating Knockout.js in ASP.NET MVC Applications, uses our Knockout.js experience to create a simple ASP.NET MVC application. We'll create a simple application in pure Knockout.js + ASP.NET MVC without external libraries. We'll cover how to create a Model in C# and connect it with the MVVM structure in JavaScript.

Chapter 4, Creating a Web Application with Knockout MVC, discusses how to move the entire business logic to the server side; the complete JavaScript code necessary on the client side will be generated automatically based on the described C# (or VB.NET) model.

Chapter 5, Advanced Features of Knockout.js, covers how to use advanced Knockout MVC features. The basic set will be enough for a very simple application. Any real application needs special concepts, such as regions, complex bindings, combined contexts, and so on. You may need to transfer some parameters to the server, write your own user scripts, or perform lazy loading of your data in the case of big data.

Chapter 6, Advanced Features of Knockout MVC, discusses how to use advanced Knockout MVC features. The basic set will be enough for a very simple application. Any real application needs special concepts, such as regions, complex bindings, combined contexts, and so on. You may need to transfer some parameters to the server, write your own user scripts, or make lazy loading of your data in the big data case.

Appendix, A Brief on Knockout MVC References and Features, lists some references and features that will be useful to readers.

What you need for this book

For this book, you need to have the following software set up:

  • Web browser: Internet Explorer, Mozilla Firefox, or Google Chrome

  • Text editor: Notepad++ or Sublime Text

  • C# IDE with ASP.NET support: Visual Studio C# Express or Visual Studio Community

You can work on Windows, Mac OS, or Linux.

Who this book is for

This book is intended for .NET developers who want to use the MVVM design pattern to create a powerful client-side JavaScript linked to server-side C# logic. Basic experience with ASP.NET, Razor, and creating web applications is needed. Also, elementary knowledge of C# or JavaScript is expected.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The model has two additional methods: GetName and GetBooks."

A block of code is set as follows:

var self = this;
self.Name = ko.observable();
self.Books = ko.observableArray();

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

var PersonViewModel = function() {
  var self = this;
  self.children = ko.observableArray(person.children);
  self.selectedChildren = ko.observable([]);

Any command-line input or output is written as follows:

PM> Install-Package bootstrap

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "In our case, we need to select the Empty MVC controller template."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.