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 ...

Get Getting Started with Knockout.js for .NET Developers 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.