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

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.