Ultimately they both produce the same HTML but Html.TextBoxFor() is strongly typed where as Html.TextBox isn't.
1: @Html.TextBox("Name")
2: Html.TextBoxFor(m => m.Name)
will both produce
<input id="Name" name="Name" type="text" />
So what does that mean in terms of use?
Generally two things:
- 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 underscore such as 'customer_name'
- Using the typed
TextBoxFor
version 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…