[Feature] Extend select tag helper #5584
Comments
@joacar , |
Thanks for pointing me to SelectList! I have used reflection directly to retrieve the values in the 'TagHelper.Init' instead of passning text and value along with objects to 'SelectList'. My proposal is hence to "include" 'SelectList' functionality in the tag helper by adding the attributes 'text,value,objects'. (Sent from phone so not sure about code formatting) |
So after some experimenting I've come up with the following. I created a class that holds the text, value and items properties. This can be created in the controller with the
and used in the view <select asp-for="Country" asp-descriptor="@ViewBag.CountriesDescriptor">
<option>-- Choose country</option>
</select> The attributes SelectListDescriptor
Modifications to SelectTagHelper
|
Closing because we are not planning to add this feature. If you end up writing your own tag helper that does this, we'd be happy to have a link to it from the readme. |
Hi,
What about adding
asp-text
,asp-value
,asp-selected
andasp-objects
to the tag helper?This would allow developers to pass a list to the
asp-objects
and specify the name of the properties that should make upSelectListItem.Text
andSelectListItem.Value
.The
asp-text
andasp-value
can be a dot separated to traverse the object to find the correct property.The
asp-selected
can take an integer that will will set theSelected
property totrue
.I will be happy to create a pull request if there is interest or if this has been rejected for some reason.
The text was updated successfully, but these errors were encountered: