Sameer Ahmed S
Sameer Ahmed S

Reputation: 1683

Getting "Value cannot be null" with HTML Helper

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

Answers (1)

Jon
Jon

Reputation: 437554

The null coalescing operator would do the trick:

@Html.Label(material.ExtendedGroup ?? "default value")

Upvotes: 12

Related Questions