Error if not nullable

Hi, Im trying to use a dropdown list in a form, the form validates using fluent validation, I find it annoying that the value of the dropdown list must be nullable, since im using an object from my webapi which represents all the values on the form, but the dropdown value must not be nullable in the database, is there a workaround to not use a nullable and still be able to make it work?
Becasue if not I would not be able to ise fluent validation plug-in.

3 Replies

SP Sureshkumar P Syncfusion Team May 4, 2020 12:10 PM UTC

Hi Raul, 
 
Greetings from Syncfusion support.  
 
Yes, we can use the dropdownlist component without nullable data type (integer). But the component was not able to clear the selected values and also not able to render without preselect data. Because, in integer data types the default value is 0. So, we cannot able to support nullable value. So, we suggest you use nullable type to avoid this type of issues.

 
We have created the sample based on your requirement. please find the sample here: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DDLWithoutNullable-748577084  
 
please check the above sample and let us know whether it suits your requirement. if not please get revert us with details 
 
Regards, 
Sureshkumar P 



RA Raul May 18, 2020 11:00 PM UTC

The proposed solution doesn't work if the SfDropDownList is inside a razor component, for example to create and edit a Vehicle object y created a razor component which has all the required fields, then I insert this component in a CreateNewVehicle razor page, and a EditVehicle razor page, if I do it this way the proposed solution doesnt work. The biggest problem if I make some fields nullable is that in that way the web api generated model wont work with validation, Im using fluent validator, to validate forms, and it only admits 1 model per form.
So, I would have the api generated model with nullable properties and at the end is a mess.


SP Sureshkumar P Syncfusion Team May 19, 2020 01:12 PM UTC

Hi Raul, 
 
Thanks for your update.  
 
As per our previous update, our dropdownlist component with integer data types is not able to render with without nullable data type. Because the integer data type is having default value as 0. So, we cannot set the null value when reset the component value. Otherwise when you have always value as value property then you can render the component without nullable property.  
 
Regards, 
Sureshkumar P 


Loader.
Up arrow icon