×

iFour Logo

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

Kapil Panchal - July 13, 2021

Listening is fun too.

Straighten your back and cherish with coffee - PLAY !

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

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.

Source: HTML Helpers

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

TModel: It is the type of model.

TProperty: It is the type of value.

Parameters

htmlhelper htmlhelper

This method extends an HTML helper instance.

expression Expression>

An expression that identifies the object with the properties to be displayed.

format String

The input is formatted using this string.

Returns

MvcHtmlString

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

 

TModel: It is the type of model.

TProperty: It is the type of value.

Parameters

htmlhelper htmlHelper

This method extends an HTML helper instance

expression Expression>

An expression that identifies the object with the properties to be displayed.

htmlAttributes Object

The HTML attributes to set for the element are contained in this object.

Returns

MvcHtmlString

For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text."

Exceptions

ArgumentException

The expression parameter is null or empty.

TextBoxFor(HtmlHelper,Expression>,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, System.Collections.Generic.IDictionary htmlAttributes);

Type Parameters

 

TModel: It is the type of model.

TProperty: It is the type of value.

Parameters

htmlhelper htmlHelper

This method extends an HTML helper instance

expression Expression>

An expression that identifies the object with the properties to be displayed.

format String

The input is formatted using this string.

htmlAttributes IDictionary

The HTML attributes to set for the element are contained in this object.

Returns

MvcHtmlString

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

 

TModel: It is the type of model.

TProperty: It is the type of value.

Parameters

htmlhelper htmlHelper

This method extends an HTML helper instance

expression Expression>

An expression that identifies the object containing the properties that should be rendered.

Returns

MvcHtmlString

For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text."

Exceptions

ArgumentException

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

 

TModel: It is the type of model.

TProperty: It is the type of value.

Parameters

htmlhelper htmlHelper

This method extends an HTML helper instance

expression Expression>

An expression that identifies the object containing the properties that should be rendered.

htmlAttributes IDictionary

The HTML attributes to set for the element are contained in this object.

Returns

MvcHtmlString

For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text."

Exceptions

ArgumentException

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

htmlhelper htmlHelper

This method extends an HTML helper instance

expression Expression>

An expression that identifies the object containing the properties that should be rendered.

format String

The input is formatted using this string.

htmlAttributes Object

The HTML attributes to set for the element are contained in this object.

Returns

MvcHtmlString

The type attribute of an input element is set to "text."

Looking for Trusted Dot Net Development Company ? For Your Business?

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

htmlhelper HtmlHelper

This method extends an HTML helper instance.

name String

The form field’s name and the ViewDataDictionary key for looking up the value

value Object

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.

format String

The input is formatted using this string.

htmlAttributes IDictionary

The HTML attributes to set for the element are contained in this object.

Returns

MvcHtmlString

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

htmlhelper HtmlHelper

This method extends an HTML helper instance.

name String

The form field’s name and the ViewDataDictionary key for looking up the value

value Object

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.

format String

The input is formatted using this string.

htmlAttributes Object

The HTML attributes to set for the element are contained in this object.

Returns

MvcHtmlString

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

htmlhelper HtmlHelper

This method extends an HTML helper instance.

name String

The form field’s name and the ViewDataDictionary key for looking up the value

value Object

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.

format String

The input is formatted using this string.

Returns

MvcHtmlString

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 returns a text input element.

		   
public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name);

Parameters

htmlHelper HtmlHelper

This method extends an HTML helper instance.

name String

The form field’s name and the ViewDataDictionary key for looking up the value

value Object

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

MvcHtmlString

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

htmlHelper HtmlHelper

This method extends an HTML helper instance.

name String

The form field’s name and the ViewDataDictionary key for looking up the value

value Object

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.

htmlAttributes IDictionary

The HTML attributes to set for the element are contained in this object.

Returns

MvcHtmlString

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

htmlHelper HtmlHelper

This method extends an HTML helper instance.

name String

The form field’s name and the ViewDataDictionary key for looking up the value

Returns

MvcHtmlString

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

htmlHelper HtmlHelper

This method extends an HTML helper instance.

name String

The form field’s name and the ViewDataDictionary key for looking up the value

value Object

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.

htmlAttributes Object

The HTML attributes to set for the element are contained in this object.

Returns

MvcHtmlString

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 Table of Content 1.Introduction 2. Create a Textbox in ASP.NET MVC 3. Html.TextBoxFor() 3.1Overloads 4. Html.TextBox() 4.1Overloads 5. Conclusion 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. 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 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: Read More: Generate Thumbnail Using Asp.net 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 TModel: It is the type of model. TProperty: It is the type of value. Parameters htmlhelper htmlhelper This method extends an HTML helper instance. expression Expression> An expression that identifies the object with the properties to be displayed. format String The input is formatted using this string. Returns MvcHtmlString 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   TModel: It is the type of model. TProperty: It is the type of value. Parameters htmlhelper htmlHelper This method extends an HTML helper instance expression Expression> An expression that identifies the object with the properties to be displayed. htmlAttributes Object The HTML attributes to set for the element are contained in this object. Returns MvcHtmlString For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text." Exceptions ArgumentException The expression parameter is null or empty. TextBoxFor(HtmlHelper,Expression>,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, System.Collections.Generic.IDictionary htmlAttributes); Type Parameters   TModel: It is the type of model. TProperty: It is the type of value. Parameters htmlhelper htmlHelper This method extends an HTML helper instance expression Expression> An expression that identifies the object with the properties to be displayed. format String The input is formatted using this string. htmlAttributes IDictionary The HTML attributes to set for the element are contained in this object. Returns MvcHtmlString 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   TModel: It is the type of model. TProperty: It is the type of value. Parameters htmlhelper htmlHelper This method extends an HTML helper instance expression Expression> An expression that identifies the object containing the properties that should be rendered. Returns MvcHtmlString For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text." Exceptions ArgumentException 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   TModel: It is the type of model. TProperty: It is the type of value. Parameters htmlhelper htmlHelper This method extends an HTML helper instance expression Expression> An expression that identifies the object containing the properties that should be rendered. htmlAttributes IDictionary The HTML attributes to set for the element are contained in this object. Returns MvcHtmlString For each property of the object represented by the expression, an HTML input element is used with the type attribute set to "text." Exceptions ArgumentException 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 htmlhelper htmlHelper This method extends an HTML helper instance expression Expression> An expression that identifies the object containing the properties that should be rendered. format String The input is formatted using this string. htmlAttributes Object The HTML attributes to set for the element are contained in this object. Returns MvcHtmlString The type attribute of an input element is set to "text." Looking for Trusted Dot Net Development Company ? For Your Business? CONNECT US 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 htmlhelper HtmlHelper This method extends an HTML helper instance. name String The form field’s name and the ViewDataDictionary key for looking up the value value Object 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. format String The input is formatted using this string. htmlAttributes IDictionary The HTML attributes to set for the element are contained in this object. Returns MvcHtmlString 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 htmlhelper HtmlHelper This method extends an HTML helper instance. name String The form field’s name and the ViewDataDictionary key for looking up the value value Object 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. format String The input is formatted using this string. htmlAttributes Object The HTML attributes to set for the element are contained in this object. Returns MvcHtmlString 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 htmlhelper HtmlHelper This method extends an HTML helper instance. name String The form field’s name and the ViewDataDictionary key for looking up the value value Object 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. format String The input is formatted using this string. Returns MvcHtmlString 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 returns a text input element. public static System.Web.Mvc.MvcHtmlString TextBox(this System.Web.Mvc.HtmlHelper htmlHelper, string name); Parameters htmlHelper HtmlHelper This method extends an HTML helper instance. name String The form field’s name and the ViewDataDictionary key for looking up the value value Object 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 MvcHtmlString 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 htmlHelper HtmlHelper This method extends an HTML helper instance. name String The form field’s name and the ViewDataDictionary key for looking up the value value Object 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. htmlAttributes IDictionary The HTML attributes to set for the element are contained in this object. Returns MvcHtmlString 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 htmlHelper HtmlHelper This method extends an HTML helper instance. name String The form field’s name and the ViewDataDictionary key for looking up the value Returns MvcHtmlString 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 htmlHelper HtmlHelper This method extends an HTML helper instance. name String The form field’s name and the ViewDataDictionary key for looking up the value value Object 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. htmlAttributes Object The HTML attributes to set for the element are contained in this object. Returns MvcHtmlString 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.

Build Your Agile Team

Enter your e-mail address Please enter valid e-mail

Categories

Ensure your sustainable growth with our team

Talk to our experts
Sustainable
Sustainable
 

Blog Our insights

Is It Worth Using Azure With Power Platforms For Financial Business?
Is It Worth Using Azure With Power Platforms For Financial Business?

The era of traditional software development is fading; Azure Cloud and Power Platform services are taking charge to run businesses of the new age. When it comes to Financial business,...

Microsoft Power BI And PowerApps Development: Transforming The Healthcare Sector
Microsoft Power BI And PowerApps Development: Transforming The Healthcare Sector

If someone had told you just a few years ago that you’d soon develop mobile apps without writing a single line of code, you might not have believed them. Yes, or no? Today, over 7...

Streamlining E-commerce Operations with Microsoft PowerApps
Streamlining E-commerce Operations with Microsoft PowerApps

In today's rapidly changing digital world, eCommerce is a dynamic industry. Every day, millions of transactions take place online, so companies are always looking for new and creative methods to improve consumer satisfaction and optimize operations.