The Attr method works very much like the JQuery attr() method. It just adds a key-value pair to the html attributes.
@Html.BuildTextbox("html5-number-box").Attr("type", "number").Attr("step", "any") @Html.BuildTextbox("html5-number-box").Attr(new {type = "number", step = "any"})
The AddClass method works very much like the jQuery addClass() method. It appends classNames to the class attribute on the current builder.
@Html.BuildPasswordFor(m => m.Password).Tooltip("Min 8 characters").AddClass("qtip")
The Data method is just like the Attr() method., except that it adds the "data-" prefix.
@Html.BuildActionLink("Home", "Index", "Home").Data("icon", IconName.Home)
The When method allows you to execute any arbitrary task against the current builder whenever the specified condition is true.
In this example, we are setting the disabled attribute as well as adding a "ui-state-disabled" class name whenever the item already exists in the shopping cart.
@(Html.BuildActionLink("Add to cart"). ControllerRoute("ShoppingCart", "AddItem"). Param("id", item.Id). When(item.IsAlreadyInCart(), x => { x.Attr("disabled", "disabled"); x.AddClass("ui-state-disabled"); }))
Or in VB .Net:
<%: Html.BuildActionLink("Add to cart"). ControllerRoute("ShoppingCart", "AddItem"). Param("id", item.Id). When(item.IsAlreadyInCart(), Sub(x) x.Attr("disabled", "disabled") x.AddClass("ui-state-disabled") End Sub)%>
There are also shortcut versions of When for specific tasks like: AttrWhen and DataWhen, AddClassWhen, CssWhen, and BindWhen
The Prop method sets a key-value pair to the Instance Data collection of the builder. Instance Data is meant to contain non-visible information about a builder. This method is mostly used by Build.Mvc internally.
@Html.BuildTextBox("password").Prop("mode", TextBoxMode.Password)
The TabIndex adds the "tabindex" attribute to the html markup [short for Attr("tabindex", value)]
@Html.BuildPasswordFor(m => m.Password).TabIndex(2)
Sets the title attribute to the html attribute collection [short for Attr("title", value)]
@Html.BuildPasswordFor(m => m.Password).Tooltip("Min 8 characters")