我正在寻找一种更简单/更干燥的方式来使用我的MVC3模型。
这就是我现在所做的(每个属性都需要被告知它使用哪种资源类型):
    public class ContactMessageModel:BaseModel
    {
        [Display(Name="ReplyToEmail_DisplayName", ResourceType = typeof(Res.Views_Contact))]
        public string ReplyToEmail {get; set; }
        [Display(Name = "ContactReason_DisplayName", ResourceType = typeof(Res.Views_Contact))]
        public string ContactReason { get; set; }这可以做到吗?
这是我想要做的(我只想为模型定义一次资源类型):
[Display(ResourceType = typeof(Res.Views_Contact))]
public class ContactMessageModel:BaseModel
{
    [Display(Name="ReplyToEmail_DisplayName")]
    public string ReplyToEmail {get; set; }
    [Display(Name = "ContactReason_DisplayName")]            
    public string ContactReason { get; set; }发布于 2016-03-02 09:42:20
可以,可以默认ResourceType。Phil Haack展示了一个示例,说明如何重写.NET的ModelMetadataProviders来完成此任务,并避免重复指定相同的ResourceType:
http://haacked.com/archive/2011/07/14/model-metadata-and-validation-localization-using-conventions.aspx/
您可以全局默认为单个ResourceType,也可以使用他定义的以下属性使用默认值修饰特定类:
public class MetadataConventionsAttribute : Attribute
{
    public Type ResourceType { get; set; }
}https://stackoverflow.com/questions/6610493
复制相似问题