FluentValidation client-side validation

后端 未结 3 1451
终归单人心
终归单人心 2020-12-30 04:32

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 v

相关标签:
3条回答
  • 2020-12-30 04:59

    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)
    
    0 讨论(0)
  • 2020-12-30 05:00

    The list of validators supported on the client is on this page and are as follows:

    • NotNull/NotEmpty (required)
    • Matches (regex)
    • InclusiveBetween (range)
    • CreditCard
    • Email
    • EqualTo (cross-property equality comparison)
    • Length
    0 讨论(0)
  • 2020-12-30 05:11

    So far i know there is no list, you could create your own client side validator so create that createrthen works also on client side

    0 讨论(0)
提交回复
热议问题