I tried to create a custom ValidationAttribute:
public class RollType : ValidationAttribute
{
public override bool IsValid(object value)
{
return false; // just for trying...
}
}
Then I created (in another class) -
[RollType]
[Range(0,4)]
public int? Try { get; set; }
on the view (I use MVC) I wrote:
<div class="editor-label">
Try:
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Try)
@Html.ValidationMessageFor(model => model.Try)
</div>
The validation for "range" works great, but not for the custom one!
What can be the problem?
RollTypeAttribute
is the recommended name for this class. You can still use[RollType]
with that new name. – Millionaire