Getting Rid of Nullability Warnings
Hi, I currently have a lot of warnings with nullability enabled.
For example, database entities, where I am sure that
string
s are required in the table, how to I get rid of the warning?8 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
= string.Empty;
what about
Expression is always true according to nullable reference types' annotations
when it actually can be null, for example Model
in a View
?you probably activated nullable-reference-types
to indicate a parameter can be null you have to add a
?
behind it's type, ie MyViewModel? model
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I'm referring to MVC's cshtml file where we can have
@model MyModel
and it doesn't seem to be nullable. But in some cases, there are cases where the model is null when the view is rendered
or maybe i'm not supposed to do that?
you can add a
?
there too, to indicate that the type is nullable:
@model MyModel?
Ooh
thanks a lot 😄