What is html helper control?

 Posted by Rajnilari2015 on 12/1/2015 | Category: ASP.NET MVC Interview questions | Views: 3012 | Points: 40

In Classic ASP.NET, we have the web form controls like

<asp:button>, <asp:textbox>,<asp:lable>,<asp:datagrid> etc
After rending at the client side, these controls gets transform to standard HTML controls like

<input type="button">,<input type="text">,<span>,<table>

Unlike Classic ASP.NET, Asp.net MVC does not provide any direct web form controls.However, they does so by providing the HTML Helper which are more lightweight in nature as compared to Classic ASP.NET web form controls.

Let us look at an example to get a more clarity on the picture

Suppose we need to have a Textbox control design in Classic ASP.NET. In that case we write

<asp:textbox id="myTxtBox" name="myTxtBox" runat="server" value="default text"/>

This get render at the browser to

<input type="text" id="myTxtBox" name="myTxtBox" value="default text""/>

The same can be achieve in Asp.net MVC by using the HTML Helper as shown below

@Html.TextBox("myTxtBox", "default text"")

From the above we can infer that, HTML Helper is like a method that returns a HTML string.

But unlike the Classic ASP.NET web form controls, HTML Helper does not have events associated with them and also does not have any view state.

Asp.net MVC provides built-in HTML Helper's, Templated Helpers. If the existing HTML Helper's does not meet the requirment, one can create Custom Html Helpers too.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response