开发者

How to disable automatic ModelState Validation for a specific Controller / Action?

开发者 https://www.devze.com 2023-03-09 04:52 出处:网络
As th开发者_C百科e title mentioned, i want to disable automatic ModelState Validation for a specific Controller / Action.

As th开发者_C百科e title mentioned, i want to disable automatic ModelState Validation for a specific Controller / Action.

Is that possible ?


Consider clearing the Modelstate dictionary in the controller action instead by calling:

Modelstate.Clear();


I think it is possible. Create custom ModelValidatorProvider.

public class CustomModelValidatorProvider 
             : DataAnnotationsModelValidatorProvider
{
    protected override IEnumerable<ModelValidator> GetValidators(
        ModelMetadata metadata, 
        ControllerContext context, 
        IEnumerable<Attribute> attributes)
    {
        return Enumerable.Empty<ModelValidator>();
    }
}

and set this provider at startup.

ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new CustomModelValidatorProvider());

How about this?

0

精彩评论

暂无评论...
验证码 换一张
取 消