HI WELCOME TO KANSIRIS

What is the difference between @html.TextBox() and @html.TextBoxFor() in ASP.net MVC?

Leave a Comment
  • @Html.TextBox("Example") is use for bind loosely type data model.it not support dynamic property.
    @html.TextBoxFor() is used for binding Strongly Type data model and also support dyanamic prperty
  • Html.TextBox() :-The Html.TextBox() Helper is the most basic of the three and actually serves to generate a textbox (an <input> element) with the appropriate values and markup so that it could be used within a form.
  • Example :- 
    @Html.TextBox("Example")
  • Html.TextBoxFor()  :-Any of the Helpers that contain the word "For" will handle the exact same functionality as the previous element, but are used to directly map a property being passed into the View through a Model. This mapping will be specified using a lamdba expression instead of an explicit string like the TextBox helper above :

    Example :-
    @Html.TextBoxFor(model => model.YourProperty).
     

0 comments:

Post a Comment

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