我正在寻找一种更简单/更简洁的方法来使用我的 MVC 3 模型的资源。
我现在就是这样做的(每个属性都需要被告知它使用的是哪种资源类型):
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; }
最佳答案
似乎不可能,因为属性实例需要访问它所在的属性,而 .NET 不支持。
关于c# - 在 C# 中为模型上的属性设置默认资源类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6610493/