You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
In the SelectTagHelper you can't use asp-items without specifying asp-for.
This does NOT work:
<selectasp-items="@Model.Categories"></select>
I can think of multiple scenarios where this might be a valid use case, the simplest one is when I want to provide my own name attribute without having a property on the view model.
Another is to use with client-side libraries for client-side content behavior not even involving using a form (my current situation)
Workaround (this DOES work):
@{
int? empty=null;
}
<selectasp-for="@empty" asp-items="@Model.Categories"></select><!-- or --><selectname="my-custom-name" asp-for="@empty" asp-items="@Model.Categories"></select>
The text was updated successfully, but these errors were encountered:
😈 Well, the better excuse is the MVC tag helpers were originally modelled after the HTML helpers. DropDownListFor() and ListBoxFor() have a similar restriction; the passed expression must not be null. 😈
My only concern is a need to muck with the IHtmlGenerator APIs to enable this scenario. It's definitely doable, just not in an hour.
dougbu
changed the title
SelectTagHelpers: asp-item shouldn't require/depend on asp-for.
SelectTagHelpers: asp-items shouldn't require/depend on asp-for.
Feb 5, 2016
In the
SelectTagHelper
you can't useasp-items
without specifyingasp-for
.This does NOT work:
I can think of multiple scenarios where this might be a valid use case, the simplest one is when I want to provide my own
name
attribute without having a property on the view model.Another is to use with client-side libraries for client-side content behavior not even involving using a form (my current situation)
Workaround (this DOES work):
The text was updated successfully, but these errors were encountered: