ASP.NET MVC - Helpers

In ASP.Net web forms, developers are using the toolbox for adding controls on any particular page. However, in ASP.NET MVC application there is no toolbox available to drag and drop HTML controls on the view. In ASP.NET MVC application, if you want to create a view it should contain HTML code. So those developers who are new to MVC especially with web forms background finds this a little hard.
To overcome this problem, ASP.NET MVC provides HtmlHelper class which contains different methods that help you create HTML controls programmatically. All HtmlHelper methods generate HTML and return the result as a string. The final HTML is generated at runtime by these functions. The HtmlHelper class is designed to generate UI and it should not be used in controllers or models.
There are different types of helper methods.
Createinputs − Creates inputs for text boxes and buttons.
Createinputs − Creates inputs for text boxes and buttons.
Createlinks − Creates links that are based on information from the routing tables.
Createlinks − Creates links that are based on information from the routing tables.
Createforms − Create form tags that can post back to our action, or to post back to an action on a different controller.
Createforms − Create form tags that can post back to our action, or to post back to an action on a different controller.
Action(String)
Overloaded. Invokes the specified child action method and returns the result as an HTML string. (Defined by ChildActionExtensions)
Action(String, Object)
Overloaded. Invokes the specified child action method with the specified parameters and returns the result as an HTML string. (Defined by ChildActionExtensions)
Action(String, RouteValueDictionary)
Overloaded. Invokes the specified child action method using the specified parameters and returns the result as an HTML string. (Defined by ChildActionExtensions)
Action(String, String)
Overloaded. Invokes the specified child action method using the specified controller name and returns the result as an HTML string. (Defined by ChildActionExtensions)
Action(String, String, Object)
Overloaded. Invokes the specified child action method using the specified parameters and controller name and returns the result as an HTML string. (Defined by ChildActionExtensions)
Action(String, String, RouteValueDictionary)
Overloaded. Invokes the specified child action method using the specified parameters and controller name and returns the result as an HTML string. (Defined by ChildActionExtensions)
ActionLink(String, String)
Overloaded. (Defined by LinkExtensions)
ActionLink(String, String, Object)
Overloaded. (Defined by LinkExtensions)
ActionLink(String, String, Object, Object)
Overloaded. (Defined by LinkExtensions)
ActionLink(String, String, RouteValueDictionary)
Overloaded. (Defined by LinkExtensions)
ActionLink(String, String, RouteValueDictionary, IDictionary<String, Object>)
Overloaded. (Defined by LinkExtensions)
ActionLink(String, String, String)
Overloaded. (Defined by LinkExtensions)
ActionLink(String, String, String, Object, Object)
Overloaded. (Defined by LinkExtensions)
ActionLink(String, String, String, RouteValueDictionary, IDictionary<String, Object>)
Overloaded. (Defined by LinkExtensions)
ActionLink(String, String, String, String, String, String, Object, Object)
Overloaded. (Defined by LinkExtensions)
ActionLink(String, String, String, String, String, String, RouteValueDictionary, IDictionary<String, Object>)
Overloaded. (Defined by LinkExtensions)
BeginForm()
Overloaded. Writes an opening <form> tag to the response. The form uses the POST method, and the request is processed by the action method for the view. (Defined by FormExtensions)
BeginForm(Object)
Overloaded. Writes an opening <form> tag to the response and includes the route values in the action attribute. The form uses the POST method, and the request is processed by the action method for the view. (Defined by FormExtensions)
BeginForm(RouteValueDictionary)
Overloaded. Writes an opening <form> tag to the response and includes the route values from the route value dictionary in the action attribute. The form uses the POST method, and the request is processed by the action method for the view. (Defined by FormExtensions.)
BeginForm(String, String)
Overloaded. Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the POST method. (Defined by FormExtensions)
BeginForm(String, String, FormMethod)
Overloaded. Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method. (Defined by FormExtensions)
BeginForm(String, String, FormMethod, IDictionary<String, Object>)
Overloaded. Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method and includes the HTML attributes from a dictionary. (Defined by FormExtensions)
BeginForm(String, String, FormMethod, Object)
Overloaded. Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method and includes the HTML attributes. (Defined by FormExtensions)
BeginForm(String, String, Object)
Overloaded. Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values. The form uses the POST method. (Defined by FormExtensions)
BeginForm(String, String, Object, FormMethod)
Overloaded. Writes an opening <form> tag to the response and sets the action tag to the specified controller, action, and route values. The form uses the specified HTTP method. (Defined by FormExtensions)
BeginForm(String, String, Object, FormMethod, Object)
Overloaded. Writes an opening <form> tag to the response and sets the action tag to the specified controller, action, and route values. The form uses the specified HTTP method and includes the HTML attributes. (Defined by FormExtensions)
BeginForm(String, String, RouteValueDictionary)
Overloaded. Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values from the route value dictionary. The form uses the POST method. (Defined by FormExtensions)
BeginForm(String, String, RouteValueDictionary, FormMethod)
Overloaded. Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values from the route value dictionary. The form uses the specified HTTP method. (Defined by FormExtensions)
BeginForm(String, String, RouteValueDictionary, FormMethod, IDictionary<String, Object>)
Overloaded. Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values from the route value dictionary. The form uses the specified HTTP method, and includes the HTML attributes from the dictionary. (Defined by FormExtensions)
BeginRouteForm(Object)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(RouteValueDictionary)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(String)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(String, FormMethod)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(String, FormMethod, IDictionary<String, Object>)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(String, FormMethod, Object)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(String, Object)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(String, Object, FormMethod)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(String, Object, FormMethod, Object)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(String, RouteValueDictionary)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(String, RouteValueDictionary, FormMethod)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
BeginRouteForm(String, RouteValueDictionary, FormMethod, IDictionary<String, Object>)
Overloaded. Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by the route target. (Defined by FormExtensions)
CheckBox(String)
Overloaded. Returns a checkbox input element by using the specified HTML helper and the name of the form field. (Defined by InputExtensions)
CheckBox(String, Boolean)
Overloaded. Returns a checkbox input element by using the specified HTML helper, the name of the form field, and a value to indicate whether the check box is selected. (Defined by InputExtensions)
CheckBox(String, Boolean, IDictionary<String, Object>)
Overloaded. Returns a checkbox input element by using the specified HTML helper, the name of the form field, a value to indicate whether the check box is selected, and the HTML attributes. (Defined by InputExtensions)
CheckBox(String, Boolean, Object)
Overloaded. Returns a checkbox input element by using the specified HTML helper, the name of the form field, a value that indicates whether the check box is selected, and the HTML attributes. (Defined by InputExtensions)
CheckBox(String, IDictionary<String, Object>)
Overloaded. Returns a checkbox input element by using the specified HTML helper, the name of the form field, and the HTML attributes. (Defined by InputExtensions)
CheckBox(String, Object)
Overloaded. Returns a checkbox input element by using the specified HTML helper, the name of the form field, and the HTML attributes. (Defined by InputExtensions)
Display(String)
Overloaded. Returns HTML markup for each property in the object that is represented by a string expression. (Defined by DisplayExtensions)
Display(String, Object)
Overloaded. Returns HTML markup for each property in the object that is represented by a string expression, using additional view data. (Defined by DisplayExtensions)
Display(String, String)
Overloaded. Returns HTML markup for each property in the object that is represented by the expression, using the specified template. (Defined by DisplayExtensions)
Display(String, String, Object)
Overloaded. Returns HTML markup for each property in the object that is represented by the expression, using the specified template and additional view data. (Defined by DisplayExtensions)
Display(String, String, String)
Overloaded. Returns HTML markup for each property in the object that is represented by the expression, using the specified template and an HTML field ID. (Defined by DisplayExtensions)
Display(String, String, String, Object)
Overloaded. Returns HTML markup for each property in the object that is represented by the expression, using the specified template, HTML field ID, and additional view data. (Defined by DisplayExtensions)
DisplayForModel()
Overloaded. Returns HTML markup for each property in the model. (Defined by DisplayExtensions)
DisplayForModel(Object)
Overloaded. Returns HTML markup for each property in the model, using additional view data. (Defined by DisplayExtensions)
DisplayForModel(String)
Overloaded. Returns HTML markup for each property in the model using the specified template. (Defined by DisplayExtensions)
DisplayForModel(String, Object)
Overloaded. Returns HTML markup for each property in the model, using the specified template and additional view data. (Defined by DisplayExtensions)
DisplayForModel(String, String)
Overloaded. Returns HTML markup for each property in the model using the specified template and HTML field ID. (Defined by DisplayExtensions)
DisplayForModel(String, String, Object)
Overloaded. Returns HTML markup for each property in the model, using the specified template, an HTML field ID, and additional view data. (Defined by DisplayExtensions)
DisplayName(String)
Gets the display name. (Defined by DisplayNameExtensions)
DisplayNameForModel()
Gets the display name for the model. (Defined by DisplayNameExtensions)
DisplayText(String)
Returns HTML markup for each property in the object that is represented by the specified expression. (Defined by DisplayTextExtensions)
DropDownList(String)
Overloaded. Returns a single-selection select element using the specified HTML helper and the name of the form field. (Defined by SelectExtensions)
DropDownList(String, IEnumerable<SelectListItem>)
Overloaded. Returns a single-selection select element using the specified HTML helper, the name of the form field, and the specified list items. (Defined by SelectExtensions)
DropDownList(String, IEnumerable<SelectListItem>, IDictionary<String, Object>)
Overloaded. Returns a single-selection select element using the specified HTML helper, the name of the form field, the specified list items, and the specified HTML attributes. (Defined by SelectExtensions)
DropDownList(String, IEnumerable<SelectListItem>, Object)
Overloaded. Returns a single-selection select element using the specified HTML helper, the name of the form field, the specified list items, and the specified HTML attributes. (Defined by SelectExtensions)
DropDownList(String, IEnumerable<SelectListItem>, String)
Overloaded. Returns a single-selection select element using the specified HTML helper, the name of the form field, the specified list items, and an option label. (Defined by SelectExtensions)
DropDownList(String, IEnumerable<SelectListItem>, String, IDictionary<String, Object>)
Overloaded. Returns a single-selection select element using the specified HTML helper, the name of the form field, the specified list items, an option label, and the specified HTML attributes. (Defined by SelectExtensions)
DropDownList(String, IEnumerable<SelectListItem>, String, Object)
Overloaded. Returns a single-selection select element using the specified HTML helper, the name of the form field, the specified list items, an option label, and the specified HTML attributes. (Defined by SelectExtensions)
DropDownList(String, String)
Overloaded. Returns a single-selection select element using the specified HTML helper, the name of the form field, and an option label. (Defined by SelectExtensions)
Editor(String)
Overloaded. Returns an HTML input element for each property in the object that is represented by the expression. (Defined by EditorExtensions)
Editor(String, Object)
Overloaded. Returns an HTML input element for each property in the object that is represented by the expression, using additional view data. (Defined by EditorExtensions)
Editor(String, String)
Overloaded. Returns an HTML input element for each property in the object that is represented by the expression, using the specified template. (Defined by EditorExtensions)
Editor(String, String, Object)
Overloaded. Returns an HTML input element for each property in the object that is represented by the expression, using the specified template and additional view data. (Defined by EditorExtensions)
Editor(String, String, String)
Overloaded. Returns an HTML input element for each property in the object that is represented by the expression, using the specified template and HTML field name. (Defined by EditorExtensions)
Editor(String, String, String, Object)
Overloaded. Returns an HTML input element for each property in the object that is represented by the expression, using the specified template, HTML field name, and additional view data. (Defined by EditorExtensions)
EditorForModel()
Overloaded. Returns an HTML input element for each property in the model. (Defined by EditorExtensions)
EditorForModel(Object)
Overloaded. Returns an HTML input element for each property in the model, using additional view data. (Defined by EditorExtensions)
EditorForModel(String)
Overloaded. Returns an HTML input element for each property in the model, using the specified template. (Defined by EditorExtensions)
EditorForModel(String, Object)
Overloaded. Returns an HTML input element for each property in the model, using the specified template and additional view data. (Defined by EditorExtensions)
EditorForModel(String, String)
Overloaded. Returns an HTML input element for each property in the model, using the specified template name and HTML field name. (Defined by EditorExtensions)
EditorForModel(String, String, Object)
Overloaded. Returns an HTML input element for each property in the model, using the template name, HTML field name, and additional view data. (Defined by EditorExtensions)
EndForm()
Renders the closing </form> tag to the response. (Defined by FormExtensions)
Hidden(String)
Overloaded. Returns a hidden input element by using the specified HTML helper and the name of the form field. (Defined by InputExtensions)
Hidden(String, Object)
Overloaded. Returns a hidden input element by using the specified HTML helper, the name of the form field, and the value. (Defined by InputExtensions)
Hidden(String, Object, IDictionary<String, Object>)
Overloaded. Returns a hidden input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. (Defined by InputExtensions)
Hidden(String, Object, Object)
Overloaded. Returns a hidden input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. (Defined by InputExtensions)
Id(String)
Gets the ID of the HtmlHelper string. (Defined by NameExtensions)
IdForModel()
Gets the ID of the HtmlHelper string. (Defined by NameExtensions)
Label(String)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression. (Defined by LabelExtensions)
Label(String, IDictionary<String, Object>)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression. (Defined by LabelExtensions)
Label(String, Object)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression. (Defined by LabelExtensions)
Label(String, String)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression using the label text. (Defined by LabelExtensions)
Label(String, String, IDictionary<String, Object>)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression. (Defined by LabelExtensions)
Label(String, String, Object)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression. (Defined by LabelExtensions)
LabelForModel()
Overloaded. Returns an HTML label element and the property name of the property that is represented by the model. (Defined by LabelExtensions)
LabelForModel(IDictionary<String, Object>)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression. (Defined by LabelExtensions)
LabelForModel(Object)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression. (Defined by LabelExtensions)
LabelForModel(String)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression using the label text. (Defined by LabelExtensions)
LabelForModel(String, IDictionary<String, Object>)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression. (Defined by LabelExtensions)
LabelForModel(String, Object)
Overloaded. Returns an HTML label element and the property name of the property that is represented by the specified expression. (Defined by LabelExtensions)
ListBox(String)
Overloaded. Returns a multi-select select element using the specified HTML helper and the name of the form field. (Defined by SelectExtensions)
ListBox(String, IEnumerable<SelectListItem>)
Overloaded. Returns a multi-select select element using the specified HTML helper, the name of the form field, and the specified list items. (Defined by SelectExtensions)
ListBox(String, IEnumerable<SelectListItem>, IDictionary<String, Object>)
Overloaded. Returns a multi-select select element using the specified HTML helper, the name of the form field, the specified list items, and the specified HMTL attributes. (Defined by SelectExtensions)
ListBox(String, IEnumerable<SelectListItem>, Object)
Overloaded. Returns a multi-select select element using the specified HTML helper, the name of the form field, and the specified list items. (Defined by SelectExtensions)
Name(String)
Gets the full HTML field name for the object that is represented by the expression. (Defined by NameExtensions)
NameForModel()
Gets the full HTML field name for the object that is represented by the expression. (Defined by NameExtensions.)
Partial(String)
Overloaded. Renders the specified partial view as an HTMLencoded string. (Defined by PartialExtensions)
Partial(String, Object)
Overloaded. Renders the specified partial view as an HTMLencoded string. (Defined by PartialExtensions)
Partial(String, Object, ViewDataDictionary)
Overloaded. Renders the specified partial view as an HTMLencoded string. (Defined by PartialExtensions)
Partial(String, ViewDataDictionary)
Overloaded. Renders the specified partial view as an HTMLencoded string. (Defined by PartialExtensions)
Password(String)
Overloaded. Returns a password input element by using the specified HTML helper and the name of the form field. (Defined by InputExtensions)
Password(String, Object)
Overloaded. Returns a password input element by using the specified HTML helper, the name of the form field, and the value. (Defined by InputExtensions)
Password(String, Object, IDictionary<String, Object>)
Overloaded. Returns a password input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. (Defined by InputExtensions)
Password(String, Object, Object)
Overloaded. Returns a password input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. (Defined by InputExtensions)
RadioButton(String, Object)
Overloaded. Returns a radio button input element that is used to present mutually exclusive options. (Defined by InputExtensions)
RadioButton(String, Object, Boolean)
Overloaded. Returns a radio button input element that is used to present mutually exclusive options. (Defined by InputExtensions)
RadioButton(String, Object, Boolean, IDictionary<String, Object>)
Overloaded. Returns a radio button input element that is used to present mutually exclusive options. (Defined by InputExtensions)
RadioButton(String, Object, Boolean, Object)
Overloaded. Returns a radio button input element that is used to present mutually exclusive options. (Defined by InputExtensions)
RadioButton(String, Object, IDictionary<String, Object>)
Overloaded. Returns a radio button input element that is used to present mutually exclusive options. (Defined by InputExtensions)
RadioButton(String, Object, Object)
Overloaded. Returns a radio button input element that is used to present mutually exclusive options. (Defined by InputExtensions)
RenderAction(String)
Overloaded. Invokes the specified child action method and renders the result inline in the parent view. (Defined by ChildActionExtensions)
RenderAction(String, Object)
Overloaded. Invokes the specified child action method using the specified parameters and renders the result inline in the parent view. (Defined by ChildActionExtensions)
RenderAction(String, RouteValueDictionary)
Overloaded. Invokes the specified child action method using the specified parameters and renders the result inline in the parent view. (Defined by ChildActionExtensions)
RenderAction(String, String)
Overloaded. Invokes the specified child action method using the specified controller name and renders the result inline in the parent view. (Defined by ChildActionExtensions)
RenderAction(String, String, Object)
Overloaded. Invokes the specified child action method using the specified parameters and controller name and renders the result inline in the parent view. (Defined by ChildActionExtensions)
RenderAction(String, String, RouteValueDictionary)
Overloaded. Invokes the specified child action method using the specified parameters and controller name and renders the result inline in the parent view. (Defined by ChildActionExtensions)
RenderPartial(String)
Overloaded. Renders the specified partial view by using the specified HTML helper. (Defined by RenderPartialExtensions)
RenderPartial(String, Object)
Overloaded. Renders the specified partial view, passing it a copy of the current ViewDataDictionary object, but with the Model property set to the specified model. (Defined by RenderPartialExtensions)
RenderPartial(String, Object, ViewDataDictionary)
Overloaded. Renders the specified partial view, replacing the partial view's ViewData property with the specified ViewDataDictionary object and setting the Model property of the view data to the specified model. (Defined by RenderPartialExtensions)
RenderPartial(String, ViewDataDictionary)
Overloaded. Renders the specified partial view, replacing its ViewData property with the specified ViewDataDictionary object. (Defined by RenderPartialExtensions)
RouteLink(String, Object)
Overloaded. (Defined by LinkExtensions)
RouteLink(String, Object, Object)
Overloaded. (Defined by LinkExtensions)
RouteLink(String, RouteValueDictionary)
Overloaded. (Defined by LinkExtensions)
RouteLink(String, RouteValueDictionary, IDictionary<String, Object>)
Overloaded. (Defined by LinkExtensions)
RouteLink(String, String)
Overloaded. (Defined by LinkExtensions)
RouteLink(String, String, Object)
Overloaded. (Defined by LinkExtensions)
RouteLink(String, String, Object, Object)
Overloaded. (Defined by LinkExtensions)
RouteLink(String, String, RouteValueDictionary)
Overloaded. (Defined by LinkExtensions)
RouteLink(String, String, RouteValueDictionary, IDictionary<String, Object>)
Overloaded. (Defined by LinkExtensions)
RouteLink(String, String, String, String, String, Object, Object)
Overloaded. (Defined by LinkExtensions)
RouteLink(String, String, String, String, String, RouteValueDictionary, IDictionary<String, Object>)
Overloaded. (Defined by LinkExtensions)
TextArea(String)
Overloaded. Returns the specified textarea element by using the specified HTML helper and the name of the form field. (Defined by TextAreaExtensions.)
TextArea(String, IDictionary<String, Object>)
Overloaded. Returns the specified textarea element by using the specified HTML helper, the name of the form field, and the specified HTML attributes. (Defined by TextAreaExtensions)
TextArea(String, Object)
Overloaded. Returns the specified textarea element by using the specified HTML helper and HTML attributes. (Defined by TextAreaExtensions)
TextArea(String, String)
Overloaded. Returns the specified textarea element by using the specified HTML helper, the name of the form field, and the text content. (Defined by TextAreaExtensions)
TextArea(String, String, IDictionary<String, Object>)
Overloaded. Returns the specified textarea element by using the specified HTML helper, the name of the form field, the text content, and the specified HTML attributes. (Defined by TextAreaExtensions)
TextArea(String, String, Int32, Int32, IDictionary<String, Object>)
Overloaded. Returns the specified textarea element by using the specified HTML helper, the name of the form field, the text content, the number of rows and columns, and the specified HTML attributes. (Defined by TextAreaExtensions)
TextArea(String, String, Int32, Int32, Object)
Overloaded. Returns the specified textarea element by using the specified HTML helper, the name of the form field, the text content, the number of rows and columns, and the specified HTML attributes. (Defined by TextAreaExtensions)
TextArea(String, String, Object)
Overloaded. Returns the specified textarea element by using the specified HTML helper, the name of the form field, the text content, and the specified HTML attributes. (Defined by TextAreaExtensions)
TextBox(String)
Overloaded. Returns a text input element by using the specified HTML helper and the name of the form field. (Defined by InputExtensions)
TextBox(String, Object)
Overloaded. Returns a text input element by using the specified HTML helper, the name of the form field, and the value. (Defined by InputExtensions)
TextBox(String, Object, IDictionary<String, Object>)
Overloaded. Returns a text input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. (Defined by InputExtensions)
TextBox(String, Object, Object)
Overloaded. Returns a text input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. (Defined by InputExtensions)
TextBox(String, Object, String)
Overloaded. Returns a text input element. (Defined by InputExtensions)
TextBox(String, Object, String, IDictionary<String, Object>)
Overloaded. Returns a text input element. (Defined by InputExtensions)
TextBox(String, Object, String, Object)
Overloaded. Returns a text input element. (Defined by InputExtensions)
Validate(String)
Retrieves the validation metadata for the specified model and applies each rule to the data field. (Defined by ValidationExtensions)
ValidationMessage(String)
Overloaded. Displays a validation message if an error exists for the specified field in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationMessage(String, IDictionary<String, Object>)
Overloaded. Displays a validation message if an error exists for the specified field in the ModelStateDictionary object. (Defined by ValidationExtensions.)
ValidationMessage(String, IDictionary<String, Object>, String)
Overloaded. Displays a validation message if an error exists for the specified entry in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationMessage(String, Object)
Overloaded. Displays a validation message if an error exists for the specified field in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationMessage(String, Object, String)
Overloaded. Displays a validation message if an error exists for the specified entry in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationMessage(String, String)
Overloaded. Displays a validation message if an error exists for the specified field in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationMessage(String, String, IDictionary<String, Object>)
Overloaded. Displays a validation message if an error exists for the specified field in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationMessage(String, String, IDictionary<String, Object>, String)
Overloaded. Displays a validation message if an error exists for the specified entry in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationMessage(String, String, Object)
Overloaded. Displays a validation message if an error exists forthe specified field in the ModelStateDictionary object. (Definedby ValidationExtensions)
ValidationMessage(String, String, Object, String)
Overloaded. Displays a validation message if an error exists for the specified entry in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationMessage(String, String, String)
Overloaded. Displays a validation message if an error exists for the specified entry in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationSummary()
Overloaded. Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationSummary(Boolean)
Overloaded. Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object and optionally displays only model-level errors. (Defined by ValidationExtensions)
ValidationSummary(Boolean, String)
Overloaded. Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object and optionally displays only model-level errors. (Defined by ValidationExtensions)
ValidationSummary(Boolean, String, IDictionary<String, Object>)
Overloaded. Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object and optionally displays only model-level errors. (Defined by ValidationExtensions)
ValidationSummary(Boolean, String, IDictionary<String, Object>, String)
Overloaded. (Defined by ValidationExtensions)
ValidationSummary(Boolean, String, Object)
Overloaded. Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object and optionally displays only model-level errors. (Defined by ValidationExtensions)
ValidationSummary(Boolean, String, Object, String)
Overloaded. (Defined by ValidationExtensions)
ValidationSummary(Boolean, String, String)
Overloaded. (Defined by ValidationExtensions)
ValidationSummary(String)
Overloaded. Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationSummary(String, IDictionary<String, Object>)
Overloaded. Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationSummary(String, IDictionary<String, Object>, String)
Overloaded. (Defined by ValidationExtensions)
ValidationSummary(String, Object)
Overloaded. Returns an unordered list (ul element) of validation messages in the ModelStateDictionary object. (Defined by ValidationExtensions)
ValidationSummary(String, Object, String)
Overloaded. (Defined by ValidationExtensions)
ValidationSummary(String, String)
Overloaded. (Defined by ValidationExtensions)
Value(String)
Overloaded. Provides a mechanism to create custom HTML markup compatible with the ASP.NET MVC model binders and templates. (Defined by ValueExtensions)
Value(String, String)
Overloaded. Provides a mechanism to create custom HTML markup compatible with the ASP.NET MVC model binders and templates. (Defined by ValueExtensions)
ValueForModel()
Overloaded. Provides a mechanism to create custom HTML markup compatible with the ASP.NET MVC model binders and templates. (Defined by ValueExtensions)
ValueForModel(String)
Overloaded. Provides a mechanism to create custom HTML markup compatible with the ASP.NET MVC model binders and templates. (Defined by ValueExtensions)
If you look at the view from the last chapter which we have generated from EmployeeController index action, you will see the number of operations that started with Html, like Html.ActionLink and Html.DisplayNameFor, etc. as shown in the following code.
@model IEnumerable<MVCSimpleApp.Models.Employee>
@{
   Layout = null;
} 

<!DOCTYPE html>
<html>
   <head>
      <meta name = "viewport" content = "width = device-width" />
      <title>Index</title>
   </head>
	
   <body>
      <p>
         @Html.ActionLink("Create New", "Create")
      </p>
		
      <table class = "table">
         <tr>
            <th>
               @Html.DisplayNameFor(model => model.Name)
            </th>
				
            <th>
               @Html.DisplayNameFor(model => model.JoiningDate)
            </th>
				
            <th>
               @Html.DisplayNameFor(model => model.Age)
            </th>
				
            <th></th>
         </tr>
			
         @foreach (var item in Model) {
            <tr>
               <td>
                  @Html.DisplayFor(modelItem => item.Name)
               </td>
					
               <td>
                  @Html.DisplayFor(modelItem => item.JoiningDate)
               </td>
					
               <td>
                  @Html.DisplayFor(modelItem => item.Age)
               </td>
					
               <td>
                  @Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
                  @Html.ActionLink("Details", "Details", new { id = item.ID }) |
                  @Html.ActionLink("Delete", "Delete", new { id = item.ID })
               </td>
            </tr>
         }
			
      </table>
   </body>
</html>
This HTML is a property that we inherit from the ViewPage base class. So, it's available in all of our views and it returns an instance of a type called HTML Helper.
Let’s take a look at a simple example in which we will enable the user to edit the employee. Hence, this edit action will be using significant numbers of different HTML Helpers.
If you look at the above code, you will see at the end the following HTML Helper methods
@Html.ActionLink("Edit", "Edit", new { id = item.ID })

In the ActionLink helper, the first parameter is of the link which is “Edit”, the second parameter is the action method in the Controller, which is also “Edit”, and the third parameter ID is of any particular employee you want to edit.
Let’s change the EmployeeController class by adding a static list and also change the index action using the following code.
public static List<Employee> empList = new List<Employee>{
   new Employee{
      ID = 1,
      Name = "Allan",
      JoiningDate = DateTime.Parse(DateTime.Today.ToString()),
      Age = 23
   },
	
   new Employee{
      ID = 2,
      Name = "Carson",
      JoiningDate = DateTime.Parse(DateTime.Today.ToString()),
      Age = 45
   },
	
   new Employee{
      ID = 3,
      Name = "Carson",
      JoiningDate = DateTime.Parse(DateTime.Today.ToString()),
      Age = 37
   },
	
   new Employee{
      ID = 4,
      Name = "Laura",
      JoiningDate = DateTime.Parse(DateTime.Today.ToString()),
      Age = 26
   },
	
};

public ActionResult Index(){
   var employees = from e in empList
   orderby e.ID
   select e;
   return View(employees);
}
Let’s update the Edit action. You will see two Edit actions one for GET and one for POST. Let’s update the Edit action for Get, which has only Id in the parameter as shown in the following code.
// GET: Employee/Edit/5
public ActionResult Edit(int id){
   List<Employee> empList = GetEmployeeList();
   var employee = empList.Single(m => m.ID == id);
   return View(employee);
}
Now, we know that we have action for Edit but we don’t have any view for these actions. So we need to add a View as well. To do this, right-click on the Edit action and select Add View.
You will see the default name for view. Select Edit from the Template dropdown and Employee from the Model class dropdown.
Following is the default implementation in the Edit view.
@model MVCSimpleApp.Models.Employee
@{
   Layout = null;
}

<!DOCTYPE html>
<html>
   <head>
      <meta name = "viewport" content = "width = device-width" />
      <title>Edit</title>
   </head>
	
   <body>
      @using (Html.BeginForm()){
         @Html.AntiForgeryToken()
         <div class = "form-horizontal">
            <h4>Employee</h4>
            <hr />
            @Html.ValidationSummary(
               true, "", new { @class = "text-danger" })
					
            @Html.HiddenFor(model => model.ID)
				
            <div class = "form-group">
               @Html.LabelFor(
                  model => model.Name, htmlAttributes: new{
                     @class = "control-label col-md-2" })
							
               <div class = "col-md-10">
                  @Html.EditorFor(model => model.Name, new{
                     htmlAttributes = new {
                        @class = "form-control" } })
								
                  @Html.ValidationMessageFor(model => model.Name, "", new{
                        @class = "text-danger" })
               </div>
					
            </div>
				
            <div class = "form-group">
               @Html.LabelFor(
                  model => model.JoiningDate, htmlAttributes: new{
                     @class = "control-label col-md-2" })
							
               <div class = "col-md-10">
                  @Html.EditorFor(
                     model => model.JoiningDate, new{
                        htmlAttributes = new{ @class = "form-control" } })
								
                  @Html.ValidationMessageFor(
                     model => model.JoiningDate, "", new{
                        @class = "text-danger" })
               </div>
					
            </div>
				
            <div class = "form-group">
               @Html.LabelFor(
                  model => model.Age, htmlAttributes: new{
                     @class = "control-label col-md-2" })
							
               <div class = "col-md-10">
                  @Html.EditorFor(
                     model => model.Age, new{
                        htmlAttributes = new{ @class = "form-control" } })
								
                  @Html.ValidationMessageFor(
                     model => model.Age, "", new{
                        @class = "text-danger" })
               </div>
					
            </div>
				
            <div class = "form-group">
               <div class = "col-md-offset-2 col-md-10">
                  <input type = "submit" value = "Save" class = "btn btn-default"/>
               </div>
            </div>
				
         </div>
      }
		
      <div>
         @Html.ActionLink("Back to List", "Index")
      </div>
		
   </body>
</html>
As you can see that there are many helper methods used. So, here “HTML.BeginForm” writes an opening Form Tag. It also ensures that the method is going to be “Post”, when the user clicks on the “Save” button.
Html.BeginForm is very useful, because it enables you to change the URL, change the method, etc.
In the above code, you will see one more HTML helper and that is “@HTML.HiddenFor”, which emits the hidden field.
MVC Framework is smart enough to figure out that this ID field is mentioned in the model class and hence it needs to be prevented from getting edited, that is why it is marked as hidden.
The Html.LabelFor HTML Helper creates the labels on the screen. The Html.ValidationMessageFor helper displays proper error message if anything is wrongly entered while making the change.
We also need to change the Edit action for POST because once you update the employee then it will call this action.
// POST: Employee/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection){
   try{
      var employee = empList.Single(m => m.ID == id);
      if (TryUpdateModel(employee)){
         //To Do:- database code
         return RedirectToAction("Index");
      }
      return View(employee);
   }catch{
      return View();
   }
}
Let’s run this application and request for the following URL http://localhost:63004/employee. You will receive the following output.
Click on the edit link on any particular employee, let’s say click on Allan edit link. You will see the following view.
Let’s change the age from 23 to 29 and click ‘Save’ button, then you will see the updated age on the Index View.

    51 Lectures 
     5.5 hours 

 Anadi Sharma

    44 Lectures 
     4.5 hours 

 Kaushik Roy Chowdhury

    42 Lectures 
     18 hours 

 SHIVPRASAD KOIRALA

    57 Lectures 
     3.5 hours 

 University Code

    40 Lectures 
     2.5 hours 

 University Code

    138 Lectures 
     9 hours 

 Bhrugen Patel
 Print
 Add Notes
 Bookmark this page