DamianEdwards / TagHelperPack

A set of useful, and possibly opinionated, Tag Helpers for ASP.NET Core
MIT License
338 stars 58 forks source link

Display/Editor `view-data-*` #51

Closed dahlbyk closed 1 year ago

dahlbyk commented 1 year ago

Works like <component param-*>:

  • <display for="Whatever" view-data-one="@("uno")" view-data-two="@("dos")" />
  • <div asp-display-for="Whatever" asp-view-data-one="@("uno")" asp-view-data-two="@("dos")" />

Or you can provide an actual IDictionary<string, object> as view-data. Specifying both view-data and view-data-* merges the individual values into view-data.

Initial Proposal (Not Supported)

Turns out simple string values (familiar from asp-route-*) don't work for IDictionary<string, object>?

  • <display for="Whatever" view-data-one="uno" view-data-two="dos" />
  • <div asp-display-for="Whatever" asp-view-data-one="uno" asp-view-data-two="dos" />

Anonymous object syntax isn't easy to support and it's not really idiomatic in Core anyway, so only passing a dictionary is allowed.

  • <display for="Whatever" view-data="@(new { one = "uno" })" />
  • <div asp-display-for="Whatever" asp-view-data="@(new { one = "uno" })" />
DamianEdwards commented 1 year ago

Would you mind rebasing this PR against the latest main changes?