This is a migrated thread and some comments may be shown as answers.

MVC - Range validation on a field that is not required

1 Answer 181 Views
Validation
This is a migrated thread and some comments may be shown as answers.
gm
Top achievements
Rank 1
gm asked on 04 Nov 2012, 08:34 PM
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?

Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 05 Nov 2012, 01:40 PM
Hi,

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.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Validation
Asked by
gm
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or