s

razor if string is null or empty return default edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 04 September 2020 | 3366

In my asp .net MVC application, I wanted to display the default image if the image is empty. I wanted to do this in the view that is the .cshtml file. Check the code below.

.cshtml razor code

<img src="@(Model.Image ?? " content="" images="" defaultimage.jpg")"="" height="50">        
                    

?? is a C# Null-Collation operator is a binary operator that simplifies checking for null values. It returns the left-hand operand if the operand is not null, otherwise it returns the right-hand operand.