Get the metadata from the resolved type instead of declared type
Hi,
I introduced my issue in this solution : https://github.com/marcusien/MetadataIssue
I got a view that expect a model as at least a ViewModelBase But, of course, I could have a ViewModel which inherits from this ViewModelBase (in my case ChildViewModel) In the Index controller action, I return the view Index.cshtml with a new instance of ChildViewModel
In the ViewModelBase, i got a virtual property that is decorated by an attribute. This attribute can be redefine in the ChildViewModel by overriding the virtual property in the ChildViewModel.
I'm trying to get the value of this attribute inside a TagHelper by checking the ValidatorMetadata. I succeed to get the attribute but it returns the attribute value declared in the ViewModelBase (which is the declared type in the razor view) instead of the actual ViewModel (which is ChildViewModel as provided by the controller action).
As you can see in my project, I can do a workaround for this case in my TagHelper but it's not a long term solution cause we need to implement a workaround in each part of the code which can know this kind of problem
Hi @marcusien. Sorry for our late response here. Is this problem still relevant for us to look into?
Hi. Yes it is still. In my case I introduced some workarounds but it is annoying to have this issue even if I understand why it's happening
@pranavkm, any thoughts regarding this? Would be great to understand the reason as well as the cost of potential fix, if there is one. Thanks!
Thank you for your feedback. We're closing this issue as the behavior discussed seems to be by design. Glad that you've found a workaround.