1

I have an ASP.NET project where I use a Kendo Numeric TextBox element. I've set a min value of 200 (in the example) and when the user enters a lower value, the input changes automatically to the min value.

Is there any way, or a property, that would enable me to avoid this and show the field in red or an error intead, rather than automatically correct to the min value?

This is my code:

@Html.Kendo()
    .NumericTextBoxFor(model => model.Example)
    .HtmlAttributes(new { style = "width: 80px;" })
    .Format("#")
    .Min(Model.MinValue)

EDIT: I forgot to say that the min value came from a web service.

javiazo
  • 1,892
  • 4
  • 26
  • 41

1 Answers1

0

You can use something like this instead that will produce the same requirements you need

public class YourModel
{
   [IntegerValidator(MinValue = 200, MaxValue = int.MaxValue, ExcludeRange = true)]
   public int Example{get;set;}
}

to get more information about this idea, please check this link IntegerValidator

and you can use for example [Range(200,int.MaxValue)] for integer and [Range(200,double.MaxValue)] for double to specify only the min value

this will work with client side validation

and if you don't want to go with this idea, i think you can handle the client side event onchange for the control numerictextboxfor and you call for e.preventdefault(); and then you can handle the value as you want

hope this will help you

Monah
  • 6,714
  • 6
  • 22
  • 52
  • thanks, that's a good question, actually it will work, but there is one thing i forgot to say in the question. I get the min value dinamically from a service, so i cant write it down in the model – javiazo Nov 06 '14 at 20:18
  • you can define a class in your application that will be inherited from the class returned from the service and then you can define custom property that you will link to the kendo numeric control in your view that has a custom validation ( GreaterThan("MinValue") where MinValue is a property returned from your service class "YourParentClass") and in this case it will work with you i think, hope this will help you – Monah Nov 06 '14 at 20:47