TextBox helper in MVC3 Razor
- Html.TextBox is the helper which renders a TextBox.
- Helpers are not controls by itself, they simply generate html markup.
It has following overloads :
Overload 1 :
This overload accepts string name, which becomes the id and name attribute.
Syntax :
<p>
@Html.TextBox("TextBox")
</p>
UI :
Rendered HTML :
<p>
<input id="TextBox" name="TextBox" type="text" value="" />
</p>
The string name passed as attribute is set as id and name attribute of the control.
Overload 2 :
This overload accepts two parameters, name and value. The value is what displayed on UI.
Syntax :
<p>
@Html.TextBox("TextBox","This is TextBox.")
</p>
UI :
Rendered HTML :
<p>
<input id="TextBox" name="TextBox" type="text" value="This is TextBox." />
</p>
Overload 3 :
This overload accepts three parameters. The name, value and htmlAttributes.
Syntax :
<p>
@Html.TextBox("TextBox", "This is TextBox.", new { style = "color:Red;" })
</p>
UI :
Rendered HTML :
<p>
<input id="TextBox" name="TextBox" style="color:Red;" type="text" value="This is TextBox." />
</p>
Overload 4 :
This overload accepts three parameters, the third parameter being the IDictionary object of htmlAttributes.
Syntax :
<p>
@Html.TextBox("TextBox", "This is TextBox.", textBox)
</p>
UI :
Rendered HTML :
<p>
<input id="TextBox" maxlength="10" name="TextBox" style="color:Red" type="text" value="This is TextBox." />
</p>
0 comments:
Post a Comment