DIFFERENCE BETWEEN @Html.TextBox and @Html.TextBoxFor MVC 4 INTERVIEW QUESTOINS

In Razor view engine we use @Html.TextBox and @Html.TextBoxFor for textbox so what is the difference between @Html.TextBox and @Html.TextBoxFor?

Finally both produce the same HTML[/align] but Html.TextBoxFor() is strongly typed with any model, where as Html.TextBox isn't.

For Example:-
@Html.TextBox("Name")
@Html.TextBoxFor(m => m.Name)
both will produce
<input id="Name" name="Name" type="textbox" />

Generally two things:
a) The typed TextBoxFor will generate your input names for you. This is usually just the property name but for properties of complex types can include an '_' such as 'customer_name'
b) Using the typed TextBoxFor version will allow you to use compile time checking. So if you change you model then you can check whether there are any errors in your views.

Comments

Archive

Contact Form

Send