This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
Tag Helpers: Add "asp-" prefix to all custom attributes on Tag Helpers that target traditional HTML elements #1618
Closed
Description
We're changing our guidance and convention such that Tag Helpers that target existing HTML elements should prefix any attributes they add or where they change the semantic meaning of an existing HTML attribute. Tag Helpers that effectively create new custom elements (e.g. <cache>
#1552) will not be prefixed, neither their tag name or attribute names. We may introduce support for defining an element prefix via the @addtaghelper
directive in the future (aspnet/Razor#88).
We'll update the following Tag Helpers:
FormTagHelper
InputTagHelper
LabelTagHelper
SelectTagHelper
ScriptTagHelper
AnchorTagHelper
Example
public class FormTagHelper : TagHelper {
[HtmlAttributeName("asp-controller")]
public string Controller { get; set; }
[HtmlAttributeName("asp-action")]
public string Action { get; set; }
}
Example Before Change
<form controller="Account" action="Login" route-returnurl="@ViewBag.ReturnUrl" method="post" class="form-horizontal" role="form">
<h4>Use a local account to log in.</h4>
<hr />
<div validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label for="UserName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input for="UserName" class="form-control" />
<span validation-for="UserName" class="text-danger"></span>
</div>
</div>
</form>
Example After Change
<form asp-controller="Account" asp-action="Login" asp-route-returnurl="@ViewBag.ReturnUrl" method="post" class="form-horizontal" role="form">
<h4>Use a local account to log in.</h4>
<hr />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="UserName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="UserName" class="form-control" />
<span asp-validation-for="UserName" class="text-danger"></span>
</div>
</div>
</form>