Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 流畅的验证从未在MVC 5的任何条件下工作_C#_Fluent_Fluentvalidation - Fatal编程技术网

C# 流畅的验证从未在MVC 5的任何条件下工作

C# 流畅的验证从未在MVC 5的任何条件下工作,c#,fluent,fluentvalidation,C#,Fluent,Fluentvalidation,我在我的项目中使用fluent验证,但它在任何条件下都不起作用。在没有任何条件的简单情况下,它可以正常工作。但当我使用dependentRule或condition时,它从未起作用。这真是令人沮丧,在阅读了Fluent文档后,我已经尝试了100多次,但没有一次对我有效。请任何人都知道为什么在条件未触发时会出现这种情况,并且有任何方法可以查看这些值 public class Employee { public string Qualification { get; set; }

我在我的项目中使用fluent验证,但它在任何条件下都不起作用。在没有任何条件的简单情况下,它可以正常工作。但当我使用dependentRule或condition时,它从未起作用。这真是令人沮丧,在阅读了Fluent文档后,我已经尝试了100多次,但没有一次对我有效。请任何人都知道为什么在条件未触发时会出现这种情况,并且有任何方法可以查看这些值

public class Employee
  {
    public string Qualification { get; set; }
    public bool IsRebadged { get; set; }

  }
public class EmployeePersonalDetailsValidator : AbstractValidator<Employee>
{
    public EmployeePersonalDetailsValidator()
    {

        Qualification();
    }
    public void Qualification()
    {
        RuleFor(dto => dto.Qualification)
         .NotEmpty()
         .When(d => d.IsRebadged == true)
         .WithMessage("Please get your Qualification updated");
    }




 <div class="col-md-3 form-group">
                    <label>Qualification</label>
                    @Html.TextBoxFor(m => m.Qualification, new { @class = "form-control", @readonly = "readonly" })                    
                    @Html.ValidationMessageFor(m => m.Qualification, "", new { @class = "text-danger" })

                </div>
我已在Global.asax中配置了相同的配置,但不起作用 Global.asax

 protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
            FluentValidationModelValidatorProvider.Configure();

        }

这是关于asp.net、控制台应用程序、winforms的吗?约翰,我想是的。在Asp.net core中,您只需将它连接到Startup.cs中,它就可以工作了。在控制台应用程序中,您必须手动调用
validator.validate(foo)
,还是不调用?@Marco啊,是的,我忘了。这就是为什么我要问这个问题。可能是op没有将其连接到Asp.NETCore中的管道,或者他只是没有调用
.validate()
。考虑到他问题中的信息,这两种可能性对我都是有效的。请告诉我们,您是如何在
应用程序\u Start()
方法中配置FluentValidation的?
 protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
            FluentValidationModelValidatorProvider.Configure();

        }