Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 组件模型反射显示资源_C#_.net_Asp.net Mvc 3_Reflection - Fatal编程技术网

C# 组件模型反射显示资源

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

我正在本地化我的asp.net Mvc应用程序。字符串放置在资源文件中。我正在使用System.ComponentModel.DataAnnotations.DisplayAttribute属性装饰我的模型,例如:

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)