Text Box Building

.Size()

This gets and sets the size of the textbox. Short for .Attr("size", int). There is also an overload for setting row and column size on a text area:

@Html.BuildTextbox("textbox-10-wide").Size(10)
@Html.BuildTextbox("textarea-10-by-20").Multiline().Size(20, 10)

 


 

.Pattern()

This extension adds the HTML5 pattern attribute (.Attr("pattern", string)), for regular expressions. For example, a text box that allows social security numbers could be written like this:

@Html.BuildTextBox("html5-social-security-number").Pattern("^\d{3}\-\d{2}\-\d{4}$")

 

.MaxLength()

This extension adds the maxlength attribute (.Attr("maxlength", string))

@Html.BuildTextBox("LastName").MaxLength(30)

 

.MinLength()

This extension adds the minlength attribute (.Attr("minlength ", string))

@Html.BuildTextBox("LastName").MinLength(4)

.Min() and .Max()

These extension add the min and max attributes which are often used in conjunction with the HTML5 number input type.

.Placeholder()

This extension adds the HTML5 placeholder attribute (.Attr("placeholder", string)), which adds a watermark to the input field in supported browsers:


.Multiline() - Renders the output using TextAreaFor instead of TextBoxFor
.SingleLine() - This is the default behavior.  Only use this to switch the render mode back to SingleLine.
.Password() - Renders the output using PasswordFor instead of TextBoxFor

Last edited Aug 26, 2012 at 7:17 AM by grcodemonkey, version 8

Comments

No comments yet.