Fluent Validation in MVC: specify RuleSet for Client-Side validation

后端 未结 3 685
自闭症患者
自闭症患者 2021-01-18 08:03

In my ASP.NET MVC 4 project I have validator for one of my view models, that contain rules definition for RuleSets. Edit ruleset used in Post action, when all c

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-18 08:46

    Documentation on this can be found in the latest FluentValidation site: https://fluentvalidation.net/aspnet#asp-net-mvc-5

    Adding the CustomizeValidator attribute to the action will apply the ruleset within the pipeline when the validator is being initialized and the model is being automatically validated.

       public ActionResult Save([CustomizeValidator(RuleSet="MyRuleset")] Customer cust) {
       // ...
       }
    

提交回复
热议问题