Reputation: 1683
I am getting a "Value cannot be null" error from the code below:
@Html.Label(material.ExtendedGroup)
ExtendedGroup
is indeed null
, but I would like to know how handle this with Razor's HTML helper -- something equivalent to Isnull(material.ExtendedGroup,"",material.ExtendedGroup)
that we do in MS SQL. Please suggest a solution.
Upvotes: 5
Views: 2617
Reputation: 437554
The null coalescing operator would do the trick:
@Html.Label(material.ExtendedGroup ?? "default value")
Upvotes: 12