Tuesday 19 July 2016

Difference between @Html.EditorFor and @Html.TextBoxFor in Asp.Net MVC in razor view?





@Html.TextBoxFor :- It will always render like an input textbox irrespective datatype of the property which is getting bind with the control.

Example:-

@Html.TextBoxFor always create a textbox (<input type=”text”>)

@Html.EditorFor :- This Html helper method is dynamic in nature. It will render HTML markup based on the datatype of the property.

If you have Boolean property in Model. To render this property in view as a checkbox.
If you have String property in Model. To render this property in view as a textbox.
If you have int property in Model. To render this property in view as a textbox type=”number”.

Example:-
@Html.EditorFor(model => model.Name)

Advantages of  @Html.EditorFor:-

We know, depending on datatype of the property @Html.EditorFor generates html markup. So think you have to change datatype  of a property, then you have to changes at all places. EditorFor control will automatically  change html markup.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.