C
C#•2y ago
kunio_kun

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 strings are required in the table, how to I get rid of the warning?
8 Replies
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
xyrile
xyrile•2y ago
= string.Empty;
kunio_kun
kunio_kun•2y ago
what about Expression is always true according to nullable reference types' annotations when it actually can be null, for example Model in a View?
undisputed world champions
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
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
kunio_kun
kunio_kun•2y ago
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?
<div id="static-configuration" class="@(Model is not null && Model.Eth0EnableDhcp ? "d-none" : "")">
<div id="static-configuration" class="@(Model is not null && Model.Eth0EnableDhcp ? "d-none" : "")">
undisputed world champions
you can add a ? there too, to indicate that the type is nullable: @model MyModel?
kunio_kun
kunio_kun•2y ago
Ooh thanks a lot 😄