What is the difference between Html.Textbox and Html.TextboxFor?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ultimately they both produce the same HTML but Html.TextBoxFor() is strongly typed where as Html.TextBox isn’t.
will both produce
So what does that mean in terms of use?
Generally two things:
TextBoxForwill generate your input names for you. This is usually just the property name but for properties of complex types can include an underscore such as ‘customer_name’TextBoxForversion will allow you to use compile time checking. So if you change your model then you can check whether there are any errors in your views.It is generally regarded as better practice to use the strongly typed versions of the HtmlHelpers that were added in MVC2.