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

Form objects

In this section, we will discuss some useful elements that will help you create HTML forms. You can create various form objects by using ko.Html, as shown in the preceding code. This approach is similar to the standard ASP MVC HTML helpers:

Razor: @ko.Html.TextBox(m => m.StringValue)
Html:  <input data-bind="value: StringValue" />

Every method has an optional parameter that defines a set of HTML attributes:

Razor: @ko.Html.RadioButton(m => m.RadioSelectedOptionValue, new { value = "Alpha" })
Html:  <input data-bind="checked : RadioSelectedOptionValue" type="radio" value="Alpha" />

In addition, you can apply additional data bindings to the created objects:

Razor: @ko.Html.TextBox(m => m.StringValue).ValueUpdate(KnockoutValueUpdateKind.AfterKeyDown) ...

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