O'Reilly logo

Getting Started with Knockout.js for .NET Developers by Andrey Akinshin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing user scripts

Knockout MVC supports a large number of different methods that allow you to write the whole application in pure C# without any line of JavaScript code. However, sometimes we need to write some JavaScript code.

For example, say we want to create a button with the click logic that a title of each book should be enclosed in quotes. If the quote is already set at the beginning or end of the book title, we shouldn't add it again. Also, we will implement this logic in JavaScript on the client side.

The Model will be as follows:

public class BookModel
{
  public string Title { get; set; }
  public string Author { get; set; }
}
public class LibraryModel
{
  public List<BookModel> Books { get; set; }
}

The Controller will be as follows:

public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required