Navigation Menu

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

Restore missing ModelMetadata properties (additional metadata) #324

Closed
dougbu opened this issue Apr 25, 2014 · 11 comments
Closed

Restore missing ModelMetadata properties (additional metadata) #324

dougbu opened this issue Apr 25, 2014 · 11 comments
Labels
Milestone

Comments

@dougbu
Copy link
Member

dougbu commented Apr 25, 2014

In addition to #323, the legacy MVC version of ModelMetadata includes the following in its public surface. May need to copy at least some of these over to WebFx for compatibility.

  • RequestValidationEnabled, looks like a model binding gap related to the [AllowHtml] attribute but that attribute doesn't seem to exist (yet?)
  • PropertiesAsArray, perhaps minor but sorting may be important in some cases
  • ShortDisplayName
  • Watermark
@yishaigalatzer yishaigalatzer added this to the Post Alpha milestone Apr 30, 2014
@yishaigalatzer yishaigalatzer removed this from the Post Alpha milestone May 23, 2014
@dougbu
Copy link
Member Author

dougbu commented Jul 24, 2014

Don't need [AllowHtml] or RequestValidationEnabled because we don't have request validation in this system. Leaving that legacy behind in MVC 5.2. Questions on need for other missing properties remain open.

@dougbu
Copy link
Member Author

dougbu commented Aug 15, 2014

One more property not present in MVC 6.0's ModelMetadata:

  • AdditionalValues, a Dictionary<string, object> which adds a property bag to ModelMetadata and together with [AdditionalMetadata] supports a non-provider way to extend ModelMetadata. Odd the interface is a concrete class rather than IDictionary<string, object>. Either way we probably want this extensibility point (including [AdditionalMetadata]) in MVC 6.0.

@dougbu dougbu changed the title Fill gaps in ModelMetadata public surface [extensibility] Give users missing ModelMetadata properties (additional metadata) Aug 28, 2014
@dougbu
Copy link
Member Author

dougbu commented Aug 28, 2014

To reiterate, MVC 5 does not rely on these ModelMetadata properties and instead provides the additional metadata for user extensions to read. But MVC 6 doesn't provide this metadata.

The remaining properties are:

  • AdditionalValues described just above and linked with the [AdditionalMetadata] attribute that also doesn't exist (yet) in MVC 6.0.
  • ShortDisplayName which it turns out MVC 5 writes based on [Display(ShortName="")] when using the non-default metadata provider (DataAnnotationsModelMetadataProvider) but never reads.
  • Watermark which it turns out MVC 5 writes based on [Display(Prompt="")] when using the non-default metadata provider (DataAnnotationsModelMetadataProvider) but never reads.

Leave PropertiesAsArray aside since it's internal, likely mostly for performance (a micro-optimization from the looks of it), and doesn't fit well in this issue.

side note: Not writing two of these properties when using the default metadata provider (CachedDataAnnotationsModelMetadataProvider) may be a minor MVC 5 bug. If we add them in MVC 6, might want to provide correct default values.

@dougbu
Copy link
Member Author

dougbu commented Jan 5, 2015

See #1758 for an interesting use case of AdditionalValues. Probably possible to create an ugly mess of static dictionaries to work around the missing property but AdditionalValues is the right way forward.

@yishaigalatzer yishaigalatzer modified the milestones: Backlog, 6.0.0-beta3 Jan 14, 2015
@yishaigalatzer
Copy link
Contributor

Moving out beyond RTM, we will bring back based on user feedback. Seems lower priority for now,

@yishaigalatzer yishaigalatzer changed the title [extensibility] Give users missing ModelMetadata properties (additional metadata) Restore missing ModelMetadata properties (additional metadata) Jan 14, 2015
@Aveline67
Copy link

Why is the watermark not imlemented and what sould I use instead ?

@dougbu
Copy link
Member Author

dougbu commented Aug 12, 2015

@Aveline67 Watermark isn't implemented in MVC 6 because, unlike most ModelMetadata properties, the framework itself doesn't use it and we had not received previous requests for the feature.

One workaround is to add the watermark to AdditionalValues. See for example how [DisplayAttribute(GroupName = "...")] is handled in AdditionalValuesMetadataProvider and how that provider is added in the Startup class for that test site.

@omuleanu
Copy link

omuleanu commented Apr 5, 2016

why is ModelMetadata.AdditionalValues a readonly dictionary, I can't Add anything to it,
in mvc 5 I was using it in custom attributes (IMetadataAware) to add values that would be used in custom helpers and editor templates

@dougbu
Copy link
Member Author

dougbu commented Apr 5, 2016

@omuleanu the ModelMetadata.AdditionalValues property is a IReadOnlyDictionary<object, object> to ensure ModelMetadata instances are immutable. Immutability is a requirement for ModelMetadata in the new system.

You should write an IDisplayMetadataProvider implementation which populates DisplayMetadataProviderContext.DisplayMetadata.AdditionalValues as you wish.

@YetaWF
Copy link

YetaWF commented Apr 9, 2017

At least AdditionalMetadata is easy to fix. Sample code implementing an AdditionalMetadataAttribute at
https://yetawf.com/BlogEntry/Title/AdditionalMetadataAttribute%20Anyone/?BlogEntry=1005

@Eilon
Copy link
Member

Eilon commented May 11, 2017

Closing because there are no plans to implement this.

@Eilon Eilon closed this as completed May 11, 2017
@Eilon Eilon added the wontfix label May 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants