<b>Start Date: </b>@employee["StartDate"].<br />
Using MVC Razor 3/C#, how can I check if employee["StartDate"]
value is null/empty in the cshtml? So that if it is, I instead display:
<b>Start Date: </b>Unknown.<br />
I tried:
@if(employee["StartDate"] == null){<b>Start Date: </b>Unknown.<br />}
but that doesn't work.
Try
<b>Start Date: </b>@(employee["StartDate"] ?? "Unknown").<br />
??
return the left-side value, or the right-side value if the left-side value is null
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With