KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Implementing custom DataAnnotationsModelMetadataProvider in ASP.NET MVC2. Assuming the object that is being rendered looks like this: - Contact : IUpdateable - Name: string - ContactType: (Lead, Prospect, Customer) and the method below is in the context of Contact.ContactType meaning that: meta.PropertyName == "ContactType" meta.ContainerType == typeof(Contact) meta.Model == ContactType.Lead (the code under question:) protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName) { var containerInstance = meta.NotSureWhatGoesHere as IUpdateable; meta.IsReadOnly = containerInstance != null && containerInstance.CanBeUpdated(meta.PropertyName); } The question : How can I obtain the instance of Contact from the metadata? (replace NotSureWhatGoesHere with the correct one)? Thanks.
Tags (comma-separated)
Save Edits
Cancel