question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CustomizeValidatorAttribute on razor page actions don't work

See original GitHub issue

Rulesets (and skip) specified with CustomizeValidatorAttribute (on razor pages model actions) don’t work on asp.net core 2.1 razor pages. Properties work fine. I tested manual validation and it works fine. So, I tried the configuration options like ImplicitlyValidateChildProperties but did not help.

My rules are simple like this;

public class PersonValidator : AbstractValidator<Person> {
	public PersonValidator() {
		RuleFor(x => x.Id).NotNull();
		RuleFor(x => x.Name).Length(0, 10);
		RuleFor(x => x.Email).EmailAddress();
		RuleFor(x => x.Age).InclusiveBetween(18, 60);
	}
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JeremySkinnercommented, Jan 5, 2019

If you don’t want automatic validation then just don’t call AddFluentValidation in your application startup.

1reaction
JeremySkinnercommented, Jan 5, 2019

Hi, the CustomizeValidatorAttribute can only be used on regular controller action parameters. It can’t be used on the page models in this way. We can look at supporting this in a future version, but I believe that asp.net core 2.1 doesn’t have the infrastructure to support this so this may have to wait until 3.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Model validation in ASP.NET Core MVC and Razor Pages
Validation attributes let you specify validation rules for model properties. The following example from the sample app shows a model class that ...
Read more >
How do I add custom validation to a Razor page? [duplicate]
1 Answer. To do custom validation, you want to inherit from IValidatableObject .
Read more >
User Input Validation in Razor Pages
Input Validation is the process whereby you ensure that values provided by the user of your Razor Pages web site are of the...
Read more >
CompareAttribute not working properly with bound ...
One possibility would be to validate the page model itself, passing a custom IValidationStrategy to ignore properties that were not bound. ( ...
Read more >
Server & Client side Validations in MVC and Razor Pages
A Complete tutorial of how we can apply server & client side validation for MVC and Razor Pages with localization.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found