1
我正在尝试为ASP.NET MVC项目创建我自己的模型验证属性。我遵循this question的建议,但无法看到如何让@Html.EditorFor()
识别我的自定义属性。我是否需要在web.config的某处注册我的自定义属性类?对此this answer的评论似乎在提出同样的问题。ASP.NET MVC启用自定义验证属性
仅供参考我创建自己的属性的原因是因为我想从Sitecore中检索字段显示名称和验证消息,并且不想真正想用大量静态方法创建类的路径来表示每个文本属性,这是我必须做的,如果我是用
public class MyModel
{
[DisplayName("Some Property")]
[Required(ErrorMessageResourceName="SomeProperty_Required", ErrorMessageResourceType=typeof(MyResourceClass))]
public string SomeProperty{ get; set; }
}
public class MyResourceClass
{
public static string SomeProperty_Required
{
get { // extract field from sitecore item }
}
//for each new field validator, I would need to add an additional
//property to retrieve the corresponding validation message
}
有没有EditorFor的重载acepts串像你正在做的,http://msdn.microsoft.com/en-us/library/ee407414(v=vs.108).aspx – Fals
糟糕,在那里有点混。那些属性可以传递给属性构造函数。现在编辑我的问题。 –
听起来像Sitecore标签在这里不相关? –