This is going to be the last post on the Html extension methods and we’re going to end with TEXTAREAS. If you’ve been following these posts, then you know what to expect: several overloads of a method which let you define the attributes you’d generally set up on a TEXTAREA control.
The simplest of the overloads of the TextArea method will let you define the name of the generated control:
<%= Html.TextArea( "name" ) %>
By default, you’ll end up with a 20 columns x 2 rows HTML TEXTAREA. If that doesn’t work for you, you can always use the overload which sets those values:
public static string TextArea(this HtmlHelper htmlHelper,
You’ll also be happy to know that all the previous “tricks” work with these helpers too. So, if you’ve got an entry on the ViewData dictionary with the same name as the one you pass to the name parameter of the methods, then the generated TEXTAREA will automatically render that value as its content.
You can also use validators with these helpers (if you want to know more about validation, please check this post). As you’d expect,you also have an overload which lets you specify the HTML attributes you which to render.
And that’s it. As you can see,the helpers to cut off the work need for generating HTML from the server side and do have similar APIs. So, if you know how to use one, you really know how to use the others. Keep tuned for more MVC stuff!