Serving Industries Worldwide

Innovative Ways - Satisfied Clientele

What is HTML Helper and explain TextBox HTML Helper in Asp.Net MVC


Listening is fun too.

Straighten your back and cherish with coffee - PLAY !

 
 

What_is_HTML_Helper_and_explain_TextBox_HTML_Helper_in_Asp.Net_MVC

Table of Content

Introduction

An HTML Helper is nothing more than a string-returning method. The HTML helper is a mechanism for rendering HTML material in a view. An extension method is used to implement HTML helpers.

HTML controls are rendered in the razor view by the HTMLHelper class. while submitting a web form, it binds the model object to HTML controls to show the value of model properties in those controls and also assigning the values of the control to the model properties.

The use of the HtmlHelper class in the razor view is shown in the following figure.

HTMLHelpers

Source: HTML Helpers

@Html is an object of the HtmlHelper class in the above figure. In razor syntax, the @symbol is used to access a server-side object. Html is a property of the HtmlHelper class, which is included in the WebViewPage base class. The HtmlHelper class includes extension methods such as ActionLink() and DisplayNameFor().

HTML elements are generated by the HtmlHelper class. For Example, @Html.ActionLink("Create New", "Create") would produce anchor tag Create New.

The HtmlHelper class has many extension methods, so you can use the extension method for HtmlHelper class for creating the various HTML controls.

The HtmlHelper methods and HTML controls rendered by each method are listed in the table below.

Extension Method Strongly Typed Method Html Control
Html.ActionLink() NA
Html.TextBox() Html.TextBoxFor()
Html.TextArea() Html.TextAreaFor()
Html.CheckBox() Html.CheckBoxFor()
Html.RadioButton() Html.RadioButtonFor()
Html.DropDownList() Html.DropDownListFor() multi-select list box:
Html.ListBox() Html.ListBoxFor()
Html.Hidden() Html.HiddenFor()
Html.Password() Html.PasswordFor() HTML text: ""
Html.Display() Html.DisplayFor() HTML text: ""
Html.Label() Html.LabelFor()
Html.Editor() Html.EditorFor() Creates HTML controls based on the data type of a model property, such as a numeric field for a double, a textbox for a string property, double, or other numeric types.

The difference between utilizing HTML tags and calling the HtmlHelper methods is that the HtmlHelper method is designed to make it simple to bind to view or model data.

Now, we will learn more about Textbox HTMLHelper in MVC:

Create a Textbox in ASP.NET MVC

TextBox() and TextBoxFor TModel, TProperty() are two extension methods in the HtmlHelper class that render the HTML textbox control input type="text" in the razor view.

Generally, The generic TextBoxFor() method is used for faster performance and fewer prons for errors.

Throughout this blog, we will use the Employee model class.

Example

public class Employee
{
    public int EmployeeId { get; set; }
    [Display(Name = "Name")]
    public string EmployeeName { get; set; }
    public int Age { get; set; }
    public string Salary { get; set; }
    public bool IsActive { get; set; }
    public string Password { get; set; }
}

Html.TextBoxFor()

TextBoxFor() is a generic extension method that produces a control with the input type="text". The model class is specified by the first type parameter, whereas the property is specified by the second type parameter. As a result, it displays the value of the model property in a textbox and Visa-versa.

The following code demonstrates how to render a textbox for the Employee model's EmployeeeName property.

Example

@model Employee

@Html.TextBoxFor(m => m.EmployeName)  

The lambda expression m => m.EmployeeName specifies the EmployeeName property to bind with a textbox in the example above. As demonstrated below, it creates an input text element with id and name attributes.

Html Result:

The class attribute is used to render a textbox in the below example.

Example

@model Employee

@Html.TextBoxFor(m => m.EmployeeName, new { @class = "form-control" })

Html Result:

There are many overloads of the TextBoxFor() method and it can be applied to the Asp.Net MVC 5.2 and above version as follows:

   


Overloads

TextBoxFor(HtmlHelper,Expression>, String)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression, string format);
Type Parameters
  1. TModel:It is the type of model.
  2. TProperty:It is the type of value.
Parameters
  1. htmlhelper htmlhelper
  2. This method extends an HTML helper instance.
  1. expression Expression>
  2. An expression that identifies the object with the properties to be displayed.
  1. format String
  2. The input is formatted using this string.
Returns
  1. MvcHtmlString
  2. The type attribute on an input element is set to "text."
TextBoxFor(HtmlHelper,Expression>, Object)

Using the specified HTML attributes it returns a text input element for each property in the object represented by the expression.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression, object htmlAttributes);
Type Parameters
  1. TModel:It is the type of model.
  1. TProperty:It is the type of value.
Parameters
  1. htmlhelper htmlHelper
  2. This method extends an HTML helper instance
  1. expression xpression>
  2. An expression that identifies the object with the properties to be displayed.
  1. htmlAttributes Object
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text."
Exceptions
  1. ArgumentException
  2. The expression parameter is null or empty.
TextBoxFor(HtmlHelper,Expression>, String, IDictionary)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression, string format, System.Collections.Generic.IDictionary htmlAttributes);
Type Parameters
  1. TModel:It is the type of model.
  1. TProperty:It is the type of value.
Parameters
  1. htmlhelper htmlHelper
  2. This method extends an HTML helper instance
  1. expression xpression>
  2. An expression that identifies the object with the properties to be displayed.
  1. format String
  2. The input is formatted using this string.
  1. htmlAttributes IDictionary
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBoxFor(HtmlHelper, Expression>)

Each property in the object represented by the supplied expression returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression);
Type Parameters
  1. TModel:It is the type of model.
  1. TProperty:It is the type of value.
Parameters
  1. htmlhelper htmlHelper
  2. This method extends an HTML helper instance.
  1. expression Expression>
  2. An expression that identifies the object containing the properties that should be rendered.
Returns
  1. MvcHtmlString
  2. For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text."
Exceptions
  1. ArgumentException
  2. The expression parameter is null or empty.
TextBoxFor(HtmlHelper,Expression>,IDictionary)

Using the specified HTML attributes it returns a text input element for each property in the object represented by the expression.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression, System.Collections.Generic.IDictionary htmlAttributes);
Type Parameters
  1. TModel:It is the type of model.
  1. TProperty:It is the type of value.
Parameters
  1. htmlhelper htmlHelper
  2. This method extends an HTML helper instance.
  1. Expression Expression>
  2. An expression that identifies the object containing the properties that should be rendered.
  1. htmlAttributes IDictionary
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text."
Exceptions
  1. ArgumentException
  2. The expression parameter is null or empty.
TextBoxFor(HtmlHelper,Expression>, String, Object)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression, string format, object htmlAttributes);
Parameters
  1. htmlhelper htmlHelper
  2. This method extends an HTML helper instance.
  1. expression Expression>
  2. An expression that identifies the object containing the properties that should be rendered.
  1. format String
  2. The input is formatted using this string.
  1. htmlAttributes Object
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
 

Looking for Trusted Dot Net Development Company ?

Your Search ends here.

 

Html.TextBox()

The TextBox() method creates an HTML control input type="text" with the supplied vaslue, name and other attributes.

public static MvcHtmlString TextBoxFor(this HtmlHelper> htmlHelper, Expression> expression, object htmlAttributes);

Because the name parameter in TextBox() is a string, it is a weakly typed method. A model object's property name can be used as the name parameter. It binds a textbox with a specific property.

Example

@model Employee

@Html.TextBox("EmployeeName")

Html Result:

There are many overloads of the TextBox() method and it can be applied to the Asp.Net MVC 5.2 and above version as follows:


Overloads

TextBox(HtmlHelper, String, Object, String, Object)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value, string format, object htmlAttributes);
Parameters
  1. htmlhelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
  1. format String
  2. The input is formatted using this string.
  1. htmlAttributes Object
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String, Object, String, IDictionary)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value, System.Collections.Generic.IDictionary htmlAttributes);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
  1. format String
  2. The input is formatted using this string.
  1. htmlAttributes IDictionary
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String, Object, String)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value, string format);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. It is the form field’s name.
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
  1. format String
  2. The input is formatted using this string.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String, Object)

Using the specified HTML helper, the name of the form field, and the value return a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String, Object, IDictionary)

Using the specified HTML helper, the name of the form field, the value, and the HTML attributes return a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value, System.Collections.Generic.IDictionary htmlAttributes);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
  1. htmlAttributes IDictionary
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String)

Using the specified HTML helper, the name of the form field returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String, Object, Object)

Using the specified HTML helper, the name of the form field, and the value, and the HTML attributes return a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value, object htmlAttributes);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
  1. htmlAttributes Object
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."

Conclusion

In this blog, we have learned about what is Html Helper and what is TextBox HTML Helper in MVC using an example. It helps you to comprehend the exact usage of Html helpers and improve your grip on Asp.Net MVC.

What is HTML Helper and explain TextBox HTML Helper in Asp.Net MVC

What_is_HTML_Helper_and_explain_TextBox_HTML_Helper_in_Asp.Net_MVC

Table of Content

Introduction

An HTML Helper is nothing more than a string-returning method. The HTML helper is a mechanism for rendering HTML material in a view. An extension method is used to implement HTML helpers.

HTML controls are rendered in the razor view by the HTMLHelper class. while submitting a web form, it binds the model object to HTML controls to show the value of model properties in those controls and also assigning the values of the control to the model properties.

The use of the HtmlHelper class in the razor view is shown in the following figure.

HTMLHelpers

Source: HTML Helpers

@Html is an object of the HtmlHelper class in the above figure. In razor syntax, the @symbol is used to access a server-side object. Html is a property of the HtmlHelper class, which is included in the WebViewPage base class. The HtmlHelper class includes extension methods such as ActionLink() and DisplayNameFor().

HTML elements are generated by the HtmlHelper class. For Example, @Html.ActionLink("Create New", "Create") would produce anchor tag Create New.

The HtmlHelper class has many extension methods, so you can use the extension method for HtmlHelper class for creating the various HTML controls.

The HtmlHelper methods and HTML controls rendered by each method are listed in the table below.

Extension Method Strongly Typed Method Html Control
Html.ActionLink() NA
Html.TextBox() Html.TextBoxFor()
Html.TextArea() Html.TextAreaFor()
Html.CheckBox() Html.CheckBoxFor()
Html.RadioButton() Html.RadioButtonFor()
Html.DropDownList() Html.DropDownListFor() multi-select list box:
Html.ListBox() Html.ListBoxFor()
Html.Hidden() Html.HiddenFor()
Html.Password() Html.PasswordFor() HTML text: ""
Html.Display() Html.DisplayFor() HTML text: ""
Html.Label() Html.LabelFor()
Html.Editor() Html.EditorFor() Creates HTML controls based on the data type of a model property, such as a numeric field for a double, a textbox for a string property, double, or other numeric types.

The difference between utilizing HTML tags and calling the HtmlHelper methods is that the HtmlHelper method is designed to make it simple to bind to view or model data.

Now, we will learn more about Textbox HTMLHelper in MVC:

Create a Textbox in ASP.NET MVC

TextBox() and TextBoxFor TModel, TProperty() are two extension methods in the HtmlHelper class that render the HTML textbox control input type="text" in the razor view.

Generally, The generic TextBoxFor() method is used for faster performance and fewer prons for errors.

Throughout this blog, we will use the Employee model class.

Example

public class Employee
{
    public int EmployeeId { get; set; }
    [Display(Name = "Name")]
    public string EmployeeName { get; set; }
    public int Age { get; set; }
    public string Salary { get; set; }
    public bool IsActive { get; set; }
    public string Password { get; set; }
}

Html.TextBoxFor()

TextBoxFor() is a generic extension method that produces a control with the input type="text". The model class is specified by the first type parameter, whereas the property is specified by the second type parameter. As a result, it displays the value of the model property in a textbox and Visa-versa.

The following code demonstrates how to render a textbox for the Employee model's EmployeeeName property.

Example

@model Employee

@Html.TextBoxFor(m => m.EmployeName)  

The lambda expression m => m.EmployeeName specifies the EmployeeName property to bind with a textbox in the example above. As demonstrated below, it creates an input text element with id and name attributes.

Html Result:

The class attribute is used to render a textbox in the below example.

Example

@model Employee

@Html.TextBoxFor(m => m.EmployeeName, new { @class = "form-control" })

Html Result:

There are many overloads of the TextBoxFor() method and it can be applied to the Asp.Net MVC 5.2 and above version as follows:

   


Overloads

TextBoxFor(HtmlHelper,Expression>, String)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression, string format);
Type Parameters
  1. TModel:It is the type of model.
  2. TProperty:It is the type of value.
Parameters
  1. htmlhelper htmlhelper
  2. This method extends an HTML helper instance.
  1. expression Expression>
  2. An expression that identifies the object with the properties to be displayed.
  1. format String
  2. The input is formatted using this string.
Returns
  1. MvcHtmlString
  2. The type attribute on an input element is set to "text."
TextBoxFor(HtmlHelper,Expression>, Object)

Using the specified HTML attributes it returns a text input element for each property in the object represented by the expression.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression, object htmlAttributes);
Type Parameters
  1. TModel:It is the type of model.
  1. TProperty:It is the type of value.
Parameters
  1. htmlhelper htmlHelper
  2. This method extends an HTML helper instance
  1. expression xpression>
  2. An expression that identifies the object with the properties to be displayed.
  1. htmlAttributes Object
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text."
Exceptions
  1. ArgumentException
  2. The expression parameter is null or empty.
TextBoxFor(HtmlHelper,Expression>, String, IDictionary)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression, string format, System.Collections.Generic.IDictionary htmlAttributes);
Type Parameters
  1. TModel:It is the type of model.
  1. TProperty:It is the type of value.
Parameters
  1. htmlhelper htmlHelper
  2. This method extends an HTML helper instance
  1. expression xpression>
  2. An expression that identifies the object with the properties to be displayed.
  1. format String
  2. The input is formatted using this string.
  1. htmlAttributes IDictionary
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBoxFor(HtmlHelper, Expression>)

Each property in the object represented by the supplied expression returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression);
Type Parameters
  1. TModel:It is the type of model.
  1. TProperty:It is the type of value.
Parameters
  1. htmlhelper htmlHelper
  2. This method extends an HTML helper instance.
  1. expression Expression>
  2. An expression that identifies the object containing the properties that should be rendered.
Returns
  1. MvcHtmlString
  2. For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text."
Exceptions
  1. ArgumentException
  2. The expression parameter is null or empty.
TextBoxFor(HtmlHelper,Expression>,IDictionary)

Using the specified HTML attributes it returns a text input element for each property in the object represented by the expression.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression, System.Collections.Generic.IDictionary htmlAttributes);
Type Parameters
  1. TModel:It is the type of model.
  1. TProperty:It is the type of value.
Parameters
  1. htmlhelper htmlHelper
  2. This method extends an HTML helper instance.
  1. Expression Expression>
  2. An expression that identifies the object containing the properties that should be rendered.
  1. htmlAttributes IDictionary
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text."
Exceptions
  1. ArgumentException
  2. The expression parameter is null or empty.
TextBoxFor(HtmlHelper,Expression>, String, Object)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBoxFor(this System.Web.Mvc.HtmlHelper htmlHelper, System.Linq.Expressions.Expression> expression, string format, object htmlAttributes);
Parameters
  1. htmlhelper htmlHelper
  2. This method extends an HTML helper instance.
  1. expression Expression>
  2. An expression that identifies the object containing the properties that should be rendered.
  1. format String
  2. The input is formatted using this string.
  1. htmlAttributes Object
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
 

Looking for Trusted Dot Net Development Company ?

Your Search ends here.

 

Html.TextBox()

The TextBox() method creates an HTML control input type="text" with the supplied vaslue, name and other attributes.

public static MvcHtmlString TextBoxFor(this HtmlHelper> htmlHelper, Expression> expression, object htmlAttributes);

Because the name parameter in TextBox() is a string, it is a weakly typed method. A model object's property name can be used as the name parameter. It binds a textbox with a specific property.

Example

@model Employee

@Html.TextBox("EmployeeName")

Html Result:

There are many overloads of the TextBox() method and it can be applied to the Asp.Net MVC 5.2 and above version as follows:


Overloads

TextBox(HtmlHelper, String, Object, String, Object)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value, string format, object htmlAttributes);
Parameters
  1. htmlhelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
  1. format String
  2. The input is formatted using this string.
  1. htmlAttributes Object
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String, Object, String, IDictionary)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value, System.Collections.Generic.IDictionary htmlAttributes);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
  1. format String
  2. The input is formatted using this string.
  1. htmlAttributes IDictionary
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String, Object, String)

It returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value, string format);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. It is the form field’s name.
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
  1. format String
  2. The input is formatted using this string.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String, Object)

Using the specified HTML helper, the name of the form field, and the value return a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String, Object, IDictionary)

Using the specified HTML helper, the name of the form field, the value, and the HTML attributes return a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value, System.Collections.Generic.IDictionary htmlAttributes);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
  1. htmlAttributes IDictionary
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String)

Using the specified HTML helper, the name of the form field returns a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."
TextBox(HtmlHelper, String, Object, Object)

Using the specified HTML helper, the name of the form field, and the value, and the HTML attributes return a text input element.

public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value, object htmlAttributes);
Parameters
  1. htmlHelper HtmlHelper
  2. This method extends an HTML helper instance.
  1. name String
  2. The form field’s name and the ViewDataDictionary key for looking up the value
  1. value Object
  2. It is the text input element's value. This is the order in which the value is retrieved- the ModelStateDictionary object, this parameter's value, the ViewDataDictionary object, and finally, in the HTML attributes, a value attribute.
  1. htmlAttributes Object
  2. The HTML attributes to set for the element are contained in this object.
Returns
  1. MvcHtmlString
  2. The type attribute of an input element is set to "text."

Conclusion

In this blog, we have learned about what is Html Helper and what is TextBox HTML Helper in MVC using an example. It helps you to comprehend the exact usage of Html helpers and improve your grip on Asp.Net MVC.