Question

I'm using ASP.NET MVC 3. I have my added my own custom validation attribute:

public class CustomAttribute : ValidationAttribute, IClientValidatable {
    private readonly string _parameter1;

    public CustomAttribute(string parameter1) {
        _parameter1 = Global.Settings[parameter1];
    }

    protected override ValidationResult IsValid(object value, ValidationContext context) {
        ...
    }

    public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) {
        yield return new ModelClientValidationRule() { 
            ErrorMessage = FormatErrorMessage(metadata.DisplayName), 
            ValidationType = "custom", 
            ValidationParameters = { { "parameter1", _parameter1 } } 
        };
    }
}

Notice how it implements IClientValidatable. This renders the parameters1 setting as a HTML 5 data attribute into the field on the page.

The problem i have is the value of the setting can change but every time it changes it still renders the old value inside the data attribute. I'm guessing this is cached somewhere. Is there anyway to remove the cache?

I'd appreciate the help. Thanks

Was it helpful?

Solution

I've found a hack to solve this. You need to restart the application. This can be done programatically using HttpRuntime.UnloadAppDomain(). Incase your application is not in full trust mode then see http://www.west-wind.com/weblog/posts/2006/Oct/08/Recycling-an-ASPNET-Application-from-within.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top