HTML and CSS Reference
In-Depth Information
Figure 3-12. The form using HTML5 controls
Generating Custom HTML
The editor templates that you have implemented are all based on the TextBox() method of the Html helper
class. The templates simply add some additional attributes such as type and placeholder . However, you can
implement templates that will output any HTML content you want. To demonstrate that, I'll show you how
to build your own helper extension that generates the markup from scratch. You will use this to replace the
EmailAddress template.
Adding a Custom Helper Class
You can create your own helper class and add it as a property of the existing Html helper class. You can then
access your custom method as:
eXerCISe 3-4. CreatING a heLper eXteNSION
in the solution Explorer, right-click the Chapter 3 project and select the Add ➤ Class
links. Enter the name Html5 when prompted for the class name.
Enter the source shown in listing 3-5.
Listing 3-5 . The initial HTML5 helper class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;
Search WWH ::

Custom Search