Let’s see how to use the input tag helper to generate an input element in a form. We have the following model which will be used by our example.
public class Student
{
public string FirstName { get; set; }
}
Now at the top of the view we define the model which will be used by our view.
@model Student
Finally, we have the form tag helper which contains our input tag helper.
<form asp-controller="Home" asp-action="Index">
<input asp-for="FirstName" />
<input class="btn btn-success" type="submit" />
</form>
This code will generate the following HTML.
<form action="/" method="post">
<input type="text" id="FirstName" name="FirstName" value="" />
<input class="btn btn-success" type="submit" />
<input name="__RequestVerificationToken" type="hidden" value="CfDJ8Cc6bJ3TWmVAoCQJZSt8GLsd1adzA4BD7-CYT8bMFX6HQ893UcdeZP6FdMy8QTXHFNfhq98orNChBbOrhPFlBIfd5cZrYQlfU2zc8ZO6GC9PDGQeqamCpS6oU8KNv6c3ZrFi5QZosjE1U_GT1oQTZDk" />
</form>