我有一个这样的 ViewModel:
public class MyViewModel
{
[Display(Name = "One_Name", ResourceType = typeof(Resources.User.Resource1))]
public string One { get; set; }
[Display(Name = "Two_Name", ResourceType = typeof(Resources.User.Resource1))]
public string Two { get; set; }
}
在第 1 页上使用,当我做这样的事情时效果很好(例如拉回资源):
@Html.LabelFor(model => model.One)
但我也想在第 2 页上使用这个 ViewModel ,但我不想将属性指向不同的资源文件(例如Resources.User.Resource2
)。
我不想欺骗课堂,但我愿意接受一些 OO 技巧。
问题是属性参数必须是字符串、常量typeof
或数组表达式。
解决这个问题的最佳方法是什么?