Reputation: 3735
In a ContentPart
some of fields defined by [Required]
attribute. but in some situations I don't want validate them.
For example in the ContentPart
i have a Boolean field which named DoNotValidate
, and when its value assigned with True
I want to prevent the requirement validation on fields and does not take any requirement error.
Upvotes: 2
Views: 252
Reputation: 2055
If you have required fields you can use another tool to check fields for example:
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (Name == "Adam")
{
yield return
new ValidationResult("Nie podales imienia", new[] { "Name" });
}
}
Properites:
public string Name {get; set;}
In HTML(MVC3):
@Html.ValidationMessageFor(m => m.Name)
@Html.TextBoxFor(m => m.Name)
If you using method GET you can use this:
[HttpGet]
[CustomAuthorize]
[GroupRequired]
[RoleRequired(RoleEnum.Edit)]
If it`s not this what you want please specify your problem much more clear
Upvotes: 1