ASP.NET MVC プロジェクト用に独自のモデル検証属性を作成しようとしています。この質問のアドバイスに従いましたが@Html.EditorFor()
、カスタム属性を認識する方法がわかりません。カスタム属性クラスを web.config のどこかに登録する必要がありますか? この回答に対するコメントは、同じことを求めているようです。
参考までに、私が独自の属性を作成する理由は、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
}