Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Improve discoverability of "htmlAttributes" entry in ViewDataDictionary #2009

Closed
Eilon opened this issue Oct 26, 2016 · 3 comments
Assignees
Labels
Pri1 High priority, do before Pri2 and Pri3
Milestone

Comments

@Eilon
Copy link
Member

Eilon commented Oct 26, 2016

From @dougbu on October 6, 2014 17:5

@Html.Editor() and @Html.EditorFor() special-case an entry named "htmlAttributes" in the ViewDataDictionary (optionally augmented using additionalViewData parameters) when executing their default templates. MVC 5.2 issue #2142 is an indication this feature needs additional documentation. Users will otherwise search for ways to control generated HTML attributes when using these methods.

Couple of details:

  • "htmlAttributes" key is case-insensitive
  • entry is handled very similarly to the htmlAttributes object passed to input helpers such as @Html.HiddenFor() and @Html.TextBox()

Copied from original issue: aspnet/Mvc#1233

@danroth27 danroth27 added bug Pri1 High priority, do before Pri2 and Pri3 labels Oct 27, 2016
@danroth27 danroth27 added this to the 1.1.0 milestone Oct 27, 2016
@tdykstra tdykstra modified the milestones: Backlog 1.1, 1.1.0 Dec 5, 2016
@tdykstra tdykstra modified the milestones: Backlog, Backlog 1.1 Dec 13, 2016
@ardalis
Copy link
Contributor

ardalis commented Jan 5, 2017

Where should this be documented? https://docs.microsoft.com/en-us/aspnet/core/mvc/views/overview seems like the closest place, currently.

@dougbu
Copy link
Member

dougbu commented Jan 5, 2017

@ardalis that page doesn't mention @Html.Editor(...) or @Html.EditorFor(...) and those are the only methods that support "htmlAttributes" keys in the ViewDataDictionary. I suggest https://docs.microsoft.com/en-us/aspnet/core/mvc/views/working-with-forms

Side notes (FYI):

  • Doesn't really matter what adds the key to ViewDataDictionary. It's most commonly done in the @Html.Editor[For]() call (using the additionalViewData parameter) because it's rare for the same HTML attributes to be correct for multiple calls in a view.
  • @Html.Display() and @Html.DisplayFor() also support additionalViewData parameters but don't check the merged ViewDataDictionary for the "htmlAttributes" key.

@Rick-Anderson
Copy link
Contributor

@ardalis can you do this under PO?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pri1 High priority, do before Pri2 and Pri3
Projects
None yet
Development

No branches or pull requests

6 participants