C# 组件模型反射显示资源
我正在本地化我的asp.net Mvc应用程序。字符串放置在资源文件中。我正在使用System.ComponentModel.DataAnnotations.DisplayAttribute属性装饰我的模型,例如:C# 组件模型反射显示资源,c#,.net,asp.net-mvc-3,reflection,C#,.net,Asp.net Mvc 3,Reflection,我正在本地化我的asp.net Mvc应用程序。字符串放置在资源文件中。我正在使用System.ComponentModel.DataAnnotations.DisplayAttribute属性装饰我的模型,例如: public class User { public virtual Guid Id { get; set; } [Display(ResourceType = typeof(ModelRes.User), Name = "LogonName")] publ
public class User
{
public virtual Guid Id { get; set; }
[Display(ResourceType = typeof(ModelRes.User), Name = "LogonName")]
public virtual string LogonName { get; set; }
[Display(ResourceType = typeof(ModelRes.User), Name = "Password")]
public virtual string Password { get; set; }
}
我每个模型(类)有一个资源文件,User.resx如下所示:
LogonName | "Logon name"
Password | "Password"
现在想象一下,对于很多属性,你都会有这样的想法。我想做的是:
[CustomDisplay(typeof(ModelRes.User))]
public class User
{
public virtual Guid Id { get; set; }
public virtual string LogonName { get; set; }
public virtual string Password { get; set; }
}
并且仍然能够在我的(剃刀)视图中使用此选项:
有没有实现类似功能的经验?您必须编写一个自定义的 然后,必须使用自定义属性和属性名称设置
ModelMetadata
变量的属性
以下是一些示例/教程
您必须编写一个自定义文件 然后,必须使用自定义属性和属性名称设置
ModelMetadata
变量的属性
以下是一些示例/教程
@Html.LabelFor(m => m.LogonName)