This is because ValidateInput is for FormValueProvider only. As for JsonValueProvider, you need to deploy your own mechanism.
Steps 1) Create a marker attribute CustomAntiXssAttribute 2) Create a custom CustomAntiXssAttribute by subclassing DefaultModelBinder 3) Overrides the BindProperty method โ โโget an attempt to value for the base property, misinform it and assign it a view model property. Check this out.
Edited: Replace the string var valueResult = bindingContext.ValueProvider.GetValue(propertyDescriptor.Name); on var valueResult = bindingContext.ValueProvider.GetValue((string.IsNullOrWhiteSpace(bindingContext.ModelName) ? string.Empty : bindingContext.ModelName + ".") + propertyDescriptor.Name); to support a nested ViewModel.
source share