Unobtrusive DateTime? Validation in MVC4

前端 未结 5 2004
情深已故
情深已故 2021-02-08 08:21

I upgraded an MVC3 solution to MVC4. After the migration, the validator is broken.

My input date, if i select German as language, is \"20.03.2013\". I get an validation

5条回答
  •  自闭症患者
    2021-02-08 08:51

    Looking through the code with ILSpy it appears to be the newly introduced ClientDataTypeModelValidatorProvider that is adding the data-val-date attribute.

    If you want to revert to MVC3 style functionality then simply removing that provider from the list of model validation providers does the trick.

    It doesn't solve the problem but in a few lines of code may remove the problems caused by jquery validation's lack of globalization.

    using System.Web.Mvc;
    
    ...
    
    protected void Application_Start()
    {
      var providers = ModelValidatorProviders.Providers;
      var clientDataTypeModelValidatorProvider = providers.OfType().FirstOrDefault();
      if ( clientDataTypeModelValidatorProvider != null )
      {
        providers.Remove( clientDataTypeModelValidatorProvider );
      }
    
      ...
    }
    

提交回复
热议问题