The AssociatedModelMetadataProvider exposes the CreateMetadata signature below:
CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
Since we only have access to the container type, the only way to obtain the container instance (e.g. the Model in Model.Foo) is using the following hack:
var target = modelAccessor.Target;
var formMetadata = target.GetType().GetField("container").GetValue(target) as Container;
CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
Since we only have access to the container type, the only way to obtain the container instance (e.g. the Model in Model.Foo) is using the following hack:
var target = modelAccessor.Target;
var formMetadata = target.GetType().GetField("container").GetValue(target) as Container;