Sharprompt
Sharprompt copied to clipboard
Prompt.Bind support for IntegerValidator (MinValue, MaxValue), DefaultValue attributes
Does Prompt.Bind support also the IntegerValidator (MinValue, MaxValue), DefaultValue attributes in the model? I tried this :
public class MyModel
{
[Display(Name = "MyParam")]
[IntegerValidator(MinValue = 1, MaxValue = 3)]
[DefaultValue(2)]
[Required]
public int MyParam { get; set; }
}
...
var myModel = Prompt.Bind<MyModel>();
but see (0) as default, and can also enter any integer value.
I think the following definition achieves the same thing.
public class MyModel
{
[Display(Name = "MyParam")]
[Range(1, 3)]
[Required]
public int MyParam { get; set; } = 2;
}
You are right, it works. Thanks! Where can I find the list with the supported annotations?
Since it uses the standard C# Validator, almost all Data Annotations classes can be used.