1

In some class, let say Class A, I have a property (of type B):

public class A {
...
[AdditionalMetadata("foo", "bar")]
public B attr {get; set;}
...
}

Later on, in my controller, I instantiate this class and make it a model:

...
A obj = new A();
return View(A);
...

Now, later on, I have a custom editor template (i.e. partial view) for the class B, and from it, I know I can get the AdditionalMetadata by: ViewData.ModelMetadata.AdditionalValues["foo"];

BUT: is there a way to get that metadata property earlier, from the controller?

igorludi
  • 1,519
  • 2
  • 18
  • 31

1 Answers1

2

That should do the job.

var modelMEtadata = ModelMetadataProviders.Current.GetMetadataForProperty(null, typeof(A), "attr");
MorioBoncz
  • 920
  • 11
  • 22