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

Basic data binding

It is possible to bind data by using ko.Bind. You can use a specific method of this object, which takes a lambda expression to specify the binding target. Both here and further on, we will show source Razor constructions and the resulting HTML code in the following way:

Razor: <span @ko.Bind.Text(m => m.MyText)>
Html:  <span data-bind="text: MyText">

It is possible to apply multiple data bindings to the element:

Razor: <span @ko.Bind.Text(m => m.MyText).Visible(m => m.MyVisible).Style("fontSize", m => m.MyFontSize)>
Html:  <span data-bind="text: MyText, visible: MyVisible, style: {fontSize : MyFontSize}">

You can define the following properties by using data bindings (you can find more information in the official Knockout MVC specification): ...

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