From Pluralsight/ASP.NET Core 6 Fundamentals
Creating a Form Using Tag Helpers
ASP.NET Core has built-in Tag Helpers for creating forms:
Form
asp-controller
to specify which controller to target on a form’s POST actionasp-action
to specify which action to target on a form’s POST actionasp-route-*
to create a route where * can be the name of a parameter we want to specify a value forasp-route
to specify which named route to useasp-antiforgery
to counter cross-site request forgery attacks
Input
Label
Textarea
Select
Validation
Get the name of the property we want to display via the asp-for
attribute on the label tag helper:<label asp-for="FirstName"></label>
…which generates this HTML:
<label for="Firstname">FirstName</label>
Form Tag Helper
The form tag helper enables CSFR attack mitigations by default.
<!-- trigger the Checkout action on current controller since no other controller specified -->
<form asp-action="Checkout"
method="post" role="form">
<!-- ... -->
</form>