27. Using the Forms Tag Helpers Flashcards
What are Form Tag Helpers?
These built-in tag helpers transform HTML form elements.
Why are Form Tag Helpers useful?
These tag helpers ensure that HTML forms reflect the application’s routing configuration and data model.
How are Form Tag Helpers used?
Tag helpers are applied to HTML elements using asp-* attributes.
Are there any pitfalls or limitations to Form Tag Helpers?
These tag helpers are reliable and predictable and present no serious issues.
Are there any alternatives to Form Tag Helpers?
You don’t have to use tag helpers and can define forms without them if you prefer.
Explain the form handling pattern?
Most HTML forms exist within a well-defined pattern, shown in Figure 27-2. First, the browser sends an HTTP GET request, which results in an HTML response containing a form, making it possible for the user to provide the application with data. The user clicks a button that submits the form data with an HTTP POST request, which allows the application to receive and process the user’s data. Once the data has been processed, a response is sent that redirects the browser to a URL that provides confirmation of the user’s actions.
This is known as the Post/Redirect/Get pattern, and the redirection is important because it means the user can click the browser’s reload button without sending another POST request, which can lead to inadvertently repeating an operation.
Explain the FormTagHelper class
The FormTagHelper class is the built-in tag helper for form elements and is used to manage the configuration of HTML forms so that they target the right action or page handler without the need to hard-code URLs. The FormTagHelper transforms form elements so they target an action method or Razor Page without the need for hard-coded URLs. The attributes supported by this tag helper work in the same way as for anchor elements, described in Chapter 26, and use attributes to provide values that help generate URLs through the ASP.NET Core routing system.