ModelState.IsValid == false with no errors
See original GitHub issueIn Version 7.3.3 I have a problem with a validator. In the Controller i can see ModelState.IsValid == false
but no errors, because ModelState.ValidationState == Unvalidated
.
Same validator works fine in version 7.3.2 (with exactly same data posted). I’m using fluent validator in an asp net core 2 application. The validator is the following PaymentModelEditEnrollValidator
public class PaymentModelEditEnrollValidator : PaymentModelEditValidator<PaymentModelEditEnroll>
{
}
public class PaymentModelEditValidator : PaymentModelEditValidator<PaymentModelEdit>
{
}
public abstract class PaymentModelEditValidator<T> : AbstractValidator<T> where T : PaymentModelEdit
{
public PaymentModelEditValidator()
{
When(en => en.CanHaveExtraPayment, () =>
{
When(en => en.Detail1.Amount.GetValueOrDefault(0) > 0, () =>
{
RuleFor(en => en.Detail1.ReasonId).NotNull().NotEmpty();
RuleFor(en => en.Detail1.TypeId).NotNull().NotEmpty();
});
When(en => en.Detail2.Amount.GetValueOrDefault(0) > 0, () =>
{
RuleFor(en => en.Detail2.ReasonId).NotNull().NotEmpty();
RuleFor(en => en.Detail2.TypeId).NotNull().NotEmpty();
});
When(en => en.Detail3 != null, () =>
{
When(en => en.Detail3.Amount.GetValueOrDefault(0) > 0, () =>
{
RuleFor(en => en.Detail3.ReasonId).NotNull().NotEmpty();
RuleFor(en => en.Detail3.TypeId).NotNull().NotEmpty();
});
});
When(en => en.Detail4 != null, () =>
{
When(en => en.Detail4.Amount.GetValueOrDefault(0) > 0, () =>
{
RuleFor(en => en.Detail4.ReasonId).NotNull().NotEmpty();
RuleFor(en => en.Detail4.TypeId).NotNull().NotEmpty();
});
});
});
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top Results From Across the Web
ModelState.IsValid == false, why?
You can iterate through the keys on the dictionary and use the IsValidField method to check if that particular field is valid. Share....
Read more >[Solved] ModelState.IsValid is always returning false in ...
I have a quick question I am updating my user and there role and my modelstate.isvalid is failing. So the user does not...
Read more >Problem with ModelState.IsValid, return false where i ...
Hello, i have a problem with "ModelState.IsValid" ... IsValid to be true, but it false, because the ModelState. ... Is there any mistake?...
Read more >Why ModelState.IsValid value getting false
Put a debug point on here 'if (ModelState.IsValid)' and after that check the all properties value inside the ModelState object.
Read more >ModelState in ASP.NET MVC
IsValid is false if any of the properties submitted have any error messages attached to them. What all of this means is that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sid-6581 I’ve pushed out 7.3.4 which should fix the issue with shutting off native aspnet core validation (this only affected child collections, not root-level models).
@JeremySkinner seems to have fixed it for me too!