【发布时间】:2018-02-09 22:57:46
【问题描述】:
我通过继承 DataAnnotationsModelMetadataProvider 并覆盖 CreateMetadata 方法创建了一个自定义提供程序:
public class CustomMetadataProvider : DataAnnotationsModelMetadataProvider
{
protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes,
Type containerType, Func<object> modelAccessor,
Type modelType, string propertyName)
{
//... code not included for brevity but execution never gets here
}
}
然后我在Global.asaxMvcApplication类中注册了它:
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
// Other code...
System.Web.ModelBinding.ModelMetadataProviders.Current =
new CustomMetadataProvider();
}
}
我放了一个断点,上面的注册正在执行,Current 正在设置中。
问题/疑问
永远不会调用CreateMetadata 方法。我还需要做什么?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-5