Tag helpers generate HTML with IntelliSense-friendly Razor syntax—forms, links, and inputs bind to model properties without manual name="" attributes.
Common tag helpers
<form asp-action="Register" method="post">
<div asp-validation-summary="ModelOnly"></div>
<label asp-for="Email"></label>
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email"></span>
<button type="submit">Register</button>
</form>
Benefits
- Correct
nameandidattributes from property names - Refactor-safe—rename property, tag helpers update
- Integration with validation attributes and ModelState
Important interview questions and answers
- Q: Tag helpers vs HTML helpers?
A: Tag helpers use HTML-like syntax; HTML helpers are C# methods—tag helpers are the modern default. - Q: asp-for purpose?
A: Binds input to model property for value, name, id, and validation metadata.
Self-check
- Which tag helper shows field-level validation errors?
- Why prefer asp-action over hard-coded URLs?