I tried to use GreaterThen validator and it looks like it doesn't support client-side validation. Is there a list of FluentValidation validators which support client-side validation?
3 Answers
The list of validators supported on the client is on this page and are as follows:
- NotNull/NotEmpty (required)
- Matches (regex)
- InclusiveBetween (range)
- CreditCard
- EqualTo (cross-property equality comparison)
- Length
2 Comments
SiberianGuy
Oh, how I missed it... Is there any specific reason why GreaterThan and similar validators are not supported on client-side?
Marius Schulz
@Idsa: Quoted from fluentvalidation.codeplex.com/discussions/256069: "The only validators that are client-side enabled out of the box are those that directly correspond to MVC's built-in client-side validators."
You can use Form Helper. It adds client-side support to Fluent-Validation.
Startup.cs
services.AddFormHelper();
With configuration: (optional)
services.AddFormHelper(new FormHelperConfiguration
{
CheckTheFormFieldsMessage = "Your custom message...",
RedirectDelay = 6000,
DebugMode = true
});
View:
var formConfig = new FormConfig(ViewContext)
{
FormId = "ProductForm",
FormTitle = "New Product",
BeforeSubmit = "ProductFormBeforeSubmit", // optional
Callback = "ProductFormCallback" // optional,
};
// <form id="@formConfig.FormId" asp-controller="Home" asp-action="Save"
// ...
@await Html.RenderFormScript(formConfig)
Controller:
[HttpPost, FormValidator]
public IActionResult Save(FormViewModel viewModel)