Using Forms

You might wonder why a book targeted at professional web developers is going to spend time covering the HTML form tag. Isn't it easy to understand?

There are two reasons:

  • The form tag is powerful. Without the form tag, the Internet would be a read-only repository of boring documentation. You wouldn't be able to search the Web, and you wouldn't be able to buy anything (even this book) over the Internet. If an evil genius stole all the form tags from every website tonight, civilization would crumble by lunchtime tomorrow.
  • Many developers coming to the MVC framework have been using ASP.NET WebForms. WebForms don't expose the full power of the form tag (you could say WebForms manages and exploits the form tag for its own purposes). It's easy to excuse the WebForms developer who forgets what the form tag is capable of — such as creating an HTTP GET request.

The Action and the Method

A form is a container for input elements: buttons, checkboxes, text inputs, and more. It's the input elements in a form that enable a user to enter information into a page and submit information to a server. But which server? And how does the information get to the server? The answers to these questions are in the two most important attributes of a form tag: the action and the method attributes.

The action attribute tells a web browser where to send the information, so naturally the action contains a URL. The URL can be relative, or in cases where you want to send information to a different ...

Get Professional ASP.NET MVC 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.