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

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

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