Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "Value cannot be null" with HTML Helper

Tags:

null

razor

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.

like image 824
sameer Avatar asked Jun 21 '12 09:06

sameer


1 Answers

The null coalescing operator would do the trick:

@Html.Label(material.ExtendedGroup ?? "default value")
like image 85
Jon Avatar answered Sep 28 '22 03:09

Jon