-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
as of tag helper label, when there is not content, the displayname is shown while if there's content the content is used.
This is good because we can use
<label asp-for="RememberMe"></label>
and
<label asp-for="RememberMe">I want to be kept logged in on every visit</label>
but there is a 'case' when we may want both, having content and providing the displayname from metadata/modelstate like this
<label asp-for="RememberMe">
<input asp-for="RememberMe" />
</label>
This will display a checkbox with empty text inside.
I can do
<label asp-for="RememberMe">
<input asp-for="RememberMe" />
@Html.NameFor(m => m.RememberMe)
</label>
This works but I need to use old HtmlHelpers to read from modelstate/metadata.
Another problem is that label should only have one input inside and checkbox taghelper adds two for the model binder to work. This has no visual problem but is not valid html.
the intended result html is:
<label for="RememberMe">
<input id="RememberMe" name="RememberMe" type="checkbox" value="true">
RememberMe
</label>
<input name="RememberMe" type="hidden" value="false">
Is this kind of support added to the label taghelper somehow?
Is there a plan to support this scenario ? (I know in MVC5 this was not possible with HtmlHelpers, but since you added tag helpers, I was hoping we have some way to sort this out)
Note that bootstrap uses this structure so checkbox is aligned well on the form http://getbootstrap.com/css/#forms-example