TextBox Html Helper in MVC

In the last chapter we have learnt little about HtmlHelper class and its method. We have already seen how to use textbox of html helper. In this chapter we will see some more html helper in MVC and its properties.

As we already know that Htmlhelper is a way to render html content. HTML helpers are implemented as extension methods.

We have already used the "TextBoxFor" html helper in previous chapter. In this chapter we will study the @Html.TextBox and some other Helper as example. 

@Html.TextBox("EmpName") 

We can get the same output with standard HTML for a textbox with id="EmpName " and name="firstname", as shown below

<input type="text" name="firtsname" id="EmpName" />

There are several overloaded versions of @Html.TextBox(). You can also set the value, along with the name, as example.

@Html.TextBox("EmpName", "Raj")

You can also set the style on Html helper textbox as

@Html.TextBox("EmpName", "Raj", new { style = "background-color:LightGreen;", title = "Please enter your name" })

You can also create a textbox that will mask your input data as follows

@Html.Password("Password")

For creating a multi-line textbox with 10 rows and 20 columns you can use the following helper.

@Html.TextArea("Comments", "", 10, 20, null)

To create a hidden textbox, use the syntax

@Html.Hidden("id")

There is no graphical user interface for hidden textbox.

To generate a label that displays "First Name" as caption.

@Html.Label("fisrtname", "First Name")