FluentValidation client-side validation

会有一股神秘感。 提交于 2019-11-29 06:31:50

问题


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?


回答1:


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



回答2:


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




回答3:


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)


来源:https://stackoverflow.com/questions/6883488/fluentvalidation-client-side-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!