MVC - Range validation on a field that is not required

2 posts, 1 answers
  1. gm
    gm avatar
    17 posts
    Member since:
    Jul 2012

    Posted 04 Nov 2012 Link to this post

    In my view model I have a nullable decimal field that is not required, but if a value is entered, it must be within a specified range:

    [Range(0.01, 1.00)]
    public decimal? Percentile { get; set; }

    If I use either of the following approaches in my view and don't enter any values into the field, the range rule triggers and prevents submission:

    @Html.TextBoxFor(m => m.Percentile, new { @class = "k-textbox k-input" }) 
    @Html.Kendo().NumericTextBoxFor(m => m.Percentile)

    This is the HTML rendered by the @Html.TextBoxFor(...)

    <input id="AllGuidelines_0__Percentile" class="k-textbox k-input" type="text" value="" name="AllGuidelines[0].Percentile" data-val-range-min="0.01" data-val-range-max="1" data-val-range="The field Percentile must be between 0.01 and 1." data-val-number="The field Starting Percentile must be a number." data-val="true">

    I'm just wondering if I'm doing something wrong or is that the intended behavior?


  2. Answer
    Rosen avatar
    3253 posts

    Posted 05 Nov 2012 Link to this post


    Indeed, you are correct about the described behavior. However, I'm happy to inform you that we managed to address it and the fix will be included in the next internal build as well as the official Q3 2012 release of KendoUI.

    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top