Chinmaya Dash
What is the difference between “HTML.TextBox” vs “HTML.TextBoxFor”?
By Chinmaya Dash in .NET on Oct 13 2016
  • Saurabh Vasani
    Aug, 2019 9

    Both is use to create textbox but HTML.Textbox is loosly type means we can pass any name whatever we want i.e HTML.TextBox(“ABC”) but in case of HTML.TextBoxFor we must use the property which are available in particular model suppose you create one model like Customer and that contains 3 properties like Firstname , Lastname and MiddleName so in this case in our view we can use this 3 properties only , if we try to pass another property like HTML.TextBoxFor(m=>m.Age) will throws an error because we are trying to create textbox for age property which is not available in our model.

    • 2
  • Chinmaya Dash
    Oct, 2016 13

    Both of them provide the same HTML output, “HTML.TextBoxFor” is strongly typed while “HTML.TextBox” isn’t. Below is a simple HTML code which just creates a simple textbox with “CustomerCode” as name.Html.TextBox("CustomerCode")Below is “Html.TextBoxFor” code which creates HTML textbox using the property name ‘CustomerCode” from object “m”.Html.TextBoxFor(m => m.CustomerCode)In the same way we have for other HTML controls like for checkbox we have “Html.CheckBox” and “Html.CheckBoxFor”.

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS