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

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

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