HTML and CSS Reference
In-Depth Information
eXerCISe 3-1. aDDING aN eDItOr teMpLate
1.
open the Register.cshtml file, which you'll find in the Views\Account folder.
2.
For the Email field, replace TextBoxFor with EditorFor . The code will look like this:
@Html.LabelFor(m =>m.Email)
@Html.EditorFor(m =>m.Email)
3.
in the solution Explorer, right-click on the Views\shared folder and select the Add ➤
new Folder links. Enter EditorTemplates for the folder name.
Caution later in the chapter i will explain how the appropriate editor template is selected for each property.
Editor templates must be in the EditorTemplates folder for the MVC framework to be able to use them. because this
folder was added to the Views\shared folder, they are available to all views in your projects. You could create the
EditorTemplates folder in the Views\Account folder. This would make them available to all views in the Account folder
but not in other folders such as the Home folder. This also allows you to create a separate set of editor templates for
each folder if you want the Home template to be different from the Account templates.
4.
Right-click the Views\shared\EditorTemplates folder and select the Add ➤ View links.
5.
in the Add View dialog box, enter EmailAddress as the view name and make sure all
the check boxes are unselected as shown in Figure 3-5 .
 
 
Search WWH ::




Custom Search