This project is read-only.

Common Methods

Attr(string name, object value)

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"})

AddClass(params string[] classNames)

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")

 


Data(string name, object value)

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)

When(bool condition, Action<T> conditionalAction)

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 DataWhenAddClassWhen, CssWhen, and BindWhen


Prop()

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)

TabIndex()

The TabIndex adds the "tabindex" attribute to the html markup [short for Attr("tabindex", value)]

@Html.BuildPasswordFor(m => m.Password).TabIndex(2)

Tooltip()

Sets the title attribute to the html attribute collection [short for Attr("title", value)]

@Html.BuildPasswordFor(m => m.Password).Tooltip("Min 8 characters")

Last edited Apr 11, 2012 at 2:41 AM by grcodemonkey, version 22

Comments

No comments yet.