Complex bindings

In some cases, we need to apply several bindings to a single element. This is easy to do; you just need to concatenate on the target binding methods. Let's update the previous example with the book read status. First, we set the binding for the status text with the Text method. Next, we set the color of the status: green for read books and red for unread books.

The Model will be as follows:

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

The Controller will be as follows:

public class LibraryController : KnockoutController { public ActionResult Index() ...

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.