I have this in my code:
SelectList(blah, \"blah\", \"blah\", cu.Customer.CustomerID.ToString())
It gives a error when it returns null, how
It depends of the type of CustomerID
.
If CustomerID
is a string then you can use the null coalescing operator:
SelectList(blah, "blah", "blah", cu.Customer.CustomerID ?? string.Empty)
If CustomerID
is a Nullable
SelectList(blah, "blah", "blah", cu.Customer.CustomerID.ToString())
This will work because the ToString() method of Nullable
returns an empty string if the instance is null
(technically if the HasValue property is false
).