Dropdown and RequiredValidators

Hello Radzen Team,
i placed some RequiredValidators at some DropDowns and wondering why nothings shows up when submitting with empty DropDowns and EF hrows an Exception on missing FK.... Constraints.

After a really long time of searching and generating test pages i found out that the DefaultValue in RequiredValidator at DropDowns must have the Value "0". If left empty the RequiredValidator doesnt work.

Please fix this.

Kind Regards

1 Like

This is expected if the value that is going to be validated is not nullable.

1 Like

Hi @enchev,
but it were extremly helpful to get a hint for such a behavior or better automatically correction from the designer.
Spending hours to find out why the Validator is not working is extremly unsatisfying.
And it is most likely to forget this "0" setting in the future.

Are there no options for the Designer to determine automatically if its necessary to set DefaultValue to "0" or not? the Validator knows the type of the component (here dropdown). What if the designer then sets the 0 automatically?
This will help to eradicate such an unhappy behavior.
And ensure a good mood of the developers :grin:

Kind Regards


In case of non nullable int, 0 is both default and a valid value. You as developer should decide which is correct.

Hi @enchev,
but is it right that the validator doesnt work if i didnt set the default to "0"?

If its left blank the validators is pointless. So what can i decide here?
"0" and it works and "blank" and validating before inserting/updating doesnt work.

I cant understand what the decision is. Sorry. Dont want to bother but i all my dropdown uses now "0" without understanding why. i dont care if it is "0" or null or blank. none of them are valid values. "0" is never a valid default value of an identity column.

Or i didnt understand what this "defaultvalue" should be. Why must it be set to "0"?

Please help me to understand the sense of this :slight_smile:

Kind regards

The only way required validator to know if something is valid is to check if the value is not default value for the current value type. Default value for nullable types is null while for non nullable type like int is 0.

Ok. I understand.

Is there a way the designer can decide if the component is a nullable or not nullable type?
This will help to avoid such a behavior.

And it were great if the designer will show an error if the validator is not bound to a component. I my case i had forgotten to set the component and the result was that clicking save on the page will do nothing. not even call the submit methode. and the app is in error mode and i must press F5 to reload to get it back to work. It was painful to find out what happens here.

Kind regards and many thanks for your patience!

I fixed this problem by usuing range data annotation in a class, range(1.mixvalue ). It will work and avoid the defult value.