【发布时间】:2012-05-05 19:38:28
【问题描述】:
我尝试创建自定义 ValidationAttribute:
public class RollType : ValidationAttribute
{
public override bool IsValid(object value)
{
return false; // just for trying...
}
}
然后我创建(在另一个类中) -
[RollType]
[Range(0,4)]
public int? Try { get; set; }
关于视图(我使用 MVC)我写道:
<div class="editor-label">
Try:
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Try)
@Html.ValidationMessageFor(model => model.Try)
</div>
“范围”的验证效果很好,但不适用于自定义!
可能是什么问题?
【问题讨论】:
-
请注意,
RollTypeAttribute是此类的推荐名称。您仍然可以将[RollType]与该新名称一起使用。
标签: c# asp.net-mvc-3 validationattribute