【发布时间】:2011-03-09 03:36:14
【问题描述】:
在 ASP.NET MVC2 中实现自定义 DataAnnotationsModelMetadataProvider。
假设正在渲染的对象如下所示:
- Contact : IUpdateable
- Name: string
- ContactType: (Lead, Prospect, Customer)
下面的方法是在Contact.ContactType的上下文中,意思是:
meta.PropertyName == "ContactType"meta.ContainerType == typeof(Contact)meta.Model == ContactType.Lead
(有问题的代码:)
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);
}
问题:如何从元数据中获取联系人的实例? (把NotSureWhatGoesHere换成正确的)?
谢谢。
【问题讨论】:
标签: c# .net asp.net asp.net-mvc