Tuesday, December 4, 2012

Interview questions on HTML Helpers


1. What are HTML Helpers ?

HTML helpers are used in a view to render HTML contents. An HTML helper, is just a method that returns a string.
These  are the equivalent of ASP.NET Web Form controls. Like a web form control, an HTML helper enables you to encapsulate the rendering of HTML.
HTML helper does not have an event model and does not use view state.

Advantages :

HTML helpers make the life of a developer easier. By taking advantage of helpers, you can build your views with far less work.
When comparing with Web Form control, HTML helpers are extremely lightweight.

2.  What is @Html.DisplayFor and @Html.EditorFor ?

By default, the EditorFor method will generate an INPUT element for each property in the object based on the type (e.g., text input for string, checkbox for boolean, etc.). DisplayFor will do the same except that it will render non-editable markup.

Eg: 

@Html.DisplayFor( model => model.Address )
@Html.EditorFor(  model => model.Address )

No comments:

Post a Comment