我编写了一个继承自范围验证属性的自定义验证,但它不起作用。这个属性的所有其他验证都运行良好。 这是Atrribute代码:
public class GraduateYearRangeAttribute : RangeAttribute
{
public GraduateYearRangeAttribute()
: base(DateTime.Today.Year, DateTime.Today.Year + 3)
{
ErrorMessage = "bla bla";
}
这是vm中的属性:
[Display(Name = "Graduate Year")]
[Required]
[GraduateYearRange]
public int GraduateYear { get; set; }
这是观点:
<div class="editor-field">
@Html.EditorFor(model => model.GraduateYear)
@Html.ValidationMessageFor(model => model.GraduateYear)
</div>
我做错了什么?