Value binding

The value binding is the most frequently used binding in DotVVM. It allows you to bind a property in the viewmodel to a property of a control in the DotHTML file, or just render the value as a text.

The data-binding works in both directions - whenever the Url property changes, the control that this property is bound to, will be updated accordingly. Also, if the user makes a change in the control, the property value will be written back to the viewmodel.

Example

Let's have the following viewmodel:

public class MyViewModel {
    ...
    public string Url { get; set; }
    ...
}

In the DotHTML markup, you can bind the property to the Text property of a TextBox control:

<dot:TextBox Text="{value: Url}" />

If you run the page and view the page source code, you'll see that DotVVM translated the binding into a Knockout data-bind attribute. DotVVM uses this popular JavaScript library to perform the data-binding and provide the MVVM experience. This is how the HTML will look like in the browser:

<input type="text" data-bind="attr: { 'href': Url }" />

Supported expressions in value binding

You can use more complex expressions in value bindings - the only requirement is that they need to be translatable to JavaScript.

See the supported expressions page for a list of methods and APIs that are supported.

If you need to use a method that DotVVM cannot translate, you can define your own JavaScript translator.

See also