开发者

How 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜