is Valid never invoke Custom Validation Attribute
public class SomeValidator : ValidationAttribute
{
public SomeValidator()
: base("Message")
{
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
开发者_JAVA百科 return new ValidationResult("ERROR");
}
And :
[SomeValidator]
public long Something { get; set; }
Why isValid method is never invoked ? (I use ASP MVC 3) Thanks for help!
You must ensure that you have a controller action taking this model as action argument:
public class MyViewModel
{
[SomeValidator]
public long Something { get; set; }
}
and then:
public ActionResult SomeAction(SomeModel model)
{
...
}
or that you call the UpdateModel
/TryUpdateModel
method:
public ActionResult SomeAction()
{
var model = new SomeModel();
if (TryUpdateModel(model))
{
}
...
}
精彩评论