Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

SelectTagHelpers: asp-items shouldn't require/depend on asp-for. #4047

Closed
Bartmax opened this issue Feb 4, 2016 · 3 comments
Closed

SelectTagHelpers: asp-items shouldn't require/depend on asp-for. #4047

Bartmax opened this issue Feb 4, 2016 · 3 comments
Assignees
Milestone

Comments

@Bartmax
Copy link

Bartmax commented Feb 4, 2016

In the SelectTagHelper you can't use asp-items without specifying asp-for.

This does NOT work:

<select asp-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;
}
<select asp-for="@empty" asp-items="@Model.Categories"></select>
<!-- or -->
<select name="my-custom-name" asp-for="@empty" asp-items="@Model.Categories"></select>
@Eilon
Copy link
Member

Eilon commented Feb 5, 2016

@DamianEdwards @dougbu any idea if this was deliberate for some reason? Or just oops?

@DamianEdwards
Copy link
Member

I ran into this myself in the localization sample and forgot to log an issue. I think was just an oops, and we should try to fix it.

@dougbu
Copy link
Member

dougbu commented Feb 5, 2016

😈 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.

@Eilon Eilon added this to the 1.0.0-rc2 milestone Feb 5, 2016
@dougbu 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants