Inner computed properties

Knockout MVC also supports simple computed properties. These properties have a JavaScript representation and can be calculated on the client without additional requests to the server. For example, let's define a computed property DisplayText for our BookModel. This property will be calculated on the basis of Author and Title.

The Model will be as follows:

public class BookModel
{
  public string Title { get; set; }
  public string Author { get; set; }

  [Computed]
  [ScriptIgnore]
  [JsonIgnore]
  public string DisplayText
  {
    get { return Author + ": " + Title; }
  }
}
public class LibraryModel
{
  public List<BookModel> Books { get; set; }
}

The Controller will be as follows:

public class LibraryController : KnockoutController { public ActionResult ...

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.