0

I have param "min_payed" in web.config.

And I have model

  public class Pay
    {
        [Required]
        [Range(10,99999999)]
        public Decimal Cost { get; set; }
    }

min value I need get from web.config

Deniska d
  • 59
  • 11

2 Answers2

1

You could write a custom range attribute that will read its min and max values from the <appSettings> section of the config file:

public class ConfigBasedRangeAttribute : RangeAttribute
{
    public ConfigBasedRangeAttribute(): 
        base(GetConfigValue("min"), GetConfigValue("max"))
    {
    }

    private static int GetConfigValue(string key)
    {
        return int.Parse(ConfigurationManager.AppSettings["key"]);
    }
}

and then decorate your model with it:

public class Pay
{
    [Required]
    [ConfigBasedRange]
    public Decimal Cost { get; set; }
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

I'm afraid you can't. You'll have to either implement IValidatableObject (and IClientValidatable for the clientside) or create your own dataannotation that checks the configuration file.

Here's another post dealing with the same issue.

Community
  • 1
  • 1
J.P.
  • 5,567
  • 3
  • 25
  • 39