Add required attributes to AnchorTagHelper and FormTagHelper.

- This involved also adding required attributes with wildcards.
- With this change AnchorTagHelpers and FormTagHelpers should no longer light up on every `<form>` or `<a>` tag.

#2581
This commit is contained in:
N. Taylor Mullen 2015-05-20 23:03:31 -07:00
parent 2a321fd622
commit e689863461
8 changed files with 20 additions and 3 deletions

View File

@ -12,7 +12,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
/// <summary>
/// <see cref="ITagHelper"/> implementation targeting &lt;a&gt; elements.
/// </summary>
[TargetElement("a")]
[TargetElement("a", Attributes = ActionAttributeName)]
[TargetElement("a", Attributes = ControllerAttributeName)]
[TargetElement("a", Attributes = FragmentAttributeName)]
[TargetElement("a", Attributes = HostAttributeName)]
[TargetElement("a", Attributes = ProtocolAttributeName)]
[TargetElement("a", Attributes = RouteAttributeName)]
[TargetElement("a", Attributes = RouteValuesDictionaryName)]
[TargetElement("a", Attributes = RouteValuesPrefix + "*")]
public class AnchorTagHelper : TagHelper
{
private const string ActionAttributeName = "asp-action";

View File

@ -12,6 +12,12 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
/// <summary>
/// <see cref="ITagHelper"/> implementation targeting &lt;form&gt; elements.
/// </summary>
[TargetElement("form", Attributes = ActionAttributeName)]
[TargetElement("form", Attributes = AntiForgeryAttributeName)]
[TargetElement("form", Attributes = ControllerAttributeName)]
[TargetElement("form", Attributes = RouteAttributeName)]
[TargetElement("form", Attributes = RouteValuesDictionaryName)]
[TargetElement("form", Attributes = RouteValuesPrefix + "*")]
public class FormTagHelper : TagHelper
{
private const string ActionAttributeName = "asp-action";

View File

@ -8,6 +8,7 @@
<h2>Form Tag Helper Test</h2>
<form></form>
<form action="/MvcTagHelper_Home/Form" method="post"></form>
<form action="/MvcTagHelper_Home/Form" method="post"><input name="__RequestVerificationToken" type="hidden" value="{0}" /></form>
<form action="/MvcTagHelper_Home/Form" method="post"></form>

View File

@ -8,6 +8,7 @@
<h2>Form Tag Helper Test</h2>
<form></form>
<form action="/MvcTagHelper_Home/Form" method="post"><input name="__RequestVerificationToken" type="hidden" value="{0}" /></form>
<form action="/MvcTagHelper_Home/Form" method="post"><input name="__RequestVerificationToken" type="hidden" value="{1}" /></form>
<form action="/MvcTagHelper_Home/Form" method="post"></form>

View File

@ -8,6 +8,7 @@
<h2>Form Tag Helper Test</h2>
<form></form>
<form action="/MvcTagHelper_Home/Form" method="post"><input name="__RequestVerificationToken" type="hidden" value="{0}" /></form>
<form action="/MvcTagHelper_Home/Form" method="post"><input name="__RequestVerificationToken" type="hidden" value="{1}" /></form>
<form action="/MvcTagHelper_Home/Form" method="post"></form>

View File

@ -10,7 +10,7 @@
<a title="&quot;the&quot; title" href="">Product List</a>
</div>
<div>
<a id="MvcTagHelperTestIndex" href="HtmlEncode[[/]]">MvcTagHelperTest Index</a>
<a id="MvcTagHelperTestIndex">MvcTagHelperTest Index</a>
</div>
<div>
<a href="HtmlEncode[[/]]">Default Controller</a>

View File

@ -10,7 +10,7 @@
<a title="&quot;the&quot; title" href="">Product List</a>
</div>
<div>
<a id="MvcTagHelperTestIndex" href="/">MvcTagHelperTest Index</a>
<a id="MvcTagHelperTestIndex">MvcTagHelperTest Index</a>
</div>
<div>
<a href="/">Default Controller</a>

View File

@ -10,6 +10,7 @@
<h2>Form Tag Helper Test</h2>
<form></form>
<form asp-controller="MvcTagHelper_Home" asp-action="Form"></form>
<form asp-controller="MvcTagHelper_Home" asp-action="Form" asp-anti-forgery="true"></form>
<form asp-controller="MvcTagHelper_Home" asp-action="Form" asp-anti-forgery="false"></form>