This question is locked. New answers and comments are not allowed.
Hello,
I was expecting that the NumericTextBox (and CurrencyTextBox and IntegerTextBox) would use the RangeAttribute to determine the MinValue and MaxValue for the control. But this seems not to be the case.
I have solved it now this way (as an example here my editor template for the decimal type):
But this does not feel good, to be forced to use reflection to get the information.
What would be the preferred way to achieve this?
Regards, Jaap
I was expecting that the NumericTextBox (and CurrencyTextBox and IntegerTextBox) would use the RangeAttribute to determine the MinValue and MaxValue for the control. But this seems not to be the case.
I have solved it now this way (as an example here my editor template for the decimal type):
@model decimal? @{ var minValue = decimal.MinValue; var maxValue = decimal.MaxValue; var attrAdapter = ViewData.ModelMetadata.GetValidators(ViewContext).OfType<RangeAttributeAdapter>().SingleOrDefault(); if (attrAdapter != null) { var attr = (System.ComponentModel.DataAnnotations.RangeAttribute)attrAdapter.GetType() .GetProperty("Attribute", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, null, typeof(System.ComponentModel.DataAnnotations.RangeAttribute), new Type[0], null) .GetValue(attrAdapter, null); minValue = Convert.ToDecimal(attr.Minimum); maxValue = Convert.ToDecimal(attr.Maximum); } } @(Html.Telerik().NumericTextBox<decimal>() .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)) .InputHtmlAttributes(new { style = "width:100%" }) .MinValue(minValue) .MaxValue(maxValue) .Value(Model) )
But this does not feel good, to be forced to use reflection to get the information.
What would be the preferred way to achieve this?
Regards, Jaap