In this recipe, we will learn how to use Form TagHelpers.
We will use the following TagHelpers:
- In the existing Form HTML tag, some TagHelper attributes:
asp-controller
asp-action
asp-route
asp-area
asp-antiforgery
- In any existing Form element, some TagHelper attributes:
asp-for
asp-items
- Associated with any existing Form element, some TagHelper attributes in order to add validation:
asp-validation-summary
asp-validation-for
Form TagHelpers make it easier for developers to create reusable components inside CSHTML views.
- Here is a typical form using the Form TagHelper:
<form asp-area="" asp-controller="Product" asp-action="AddProduct" method="post" asp-antiforgery="true"> <div asp-validation-summary="All"></div> <div class="form-group"> <label asp-for="Name"></label> <input type="text" asp-for="Name" /> <span asp-validation-for="Name" class="text-danger"></span> </div> <...