ASP.NET MVC 2 has built-in support for the following
strongly-typed HTML helpers:
HTML Element Helpers:
Html.TextBoxFor()
Html.TextAreaFor()
Html.DropDownListFor()
Html.CheckboxFor()
Html.RadioButtonFor()
Html.ListBoxFor()
Html.PasswordFor()
Html.HiddenFor()
Html.LabelFor()
Other Helpers:
Html.EditorFor()
Html.DisplayFor()
Html.DisplayTextFor()
Html.ValidationMessageFor()
I’ll be covering the new Html.EditorFor() and Html.DisplayFor()
helper methods in a later blog post in this series when I cover the improved
auto-scaffold functionality in ASP.NET MVC 2. We’ll also be using the
Html.ValidationMessageFor() helper in my next blog post in this series which
covers the improved validation support within ASP.NET MVC 2.
Strongly-Typed HTML Helpers within Scaffolding
VS 2008 and VS 2010 both by default now use the new
strongly-typed HTML helpers when “scaffolding” new strongly-typed view tempates
using the “Add View” command.
For example, let’s assume we had a simple
“ProductsController” class like below that has an “Edit” action method that
renders an edit form for a “Product” model class:
Figure 6
We can right-click within the Edit action method using
Visual Studio and choose the “Add View” context menu command to create a view
template. We’ll choose to create an “Edit” template that is scaffolded
using a Product object:
Figure 7
With ASP.NET MVC 2, the view template that is created by
default now uses the new strongly typed HTML helper methods to reference the
Product model object:
Figure 8