Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if Viewbag property is empty, and using default value in a view

I have this piece of code in a MVC view that works, but it seams like a lot of code to achieve this simple thing. Any way to make it more efficient?

@if (string.IsNullOrEmpty(ViewBag.Name))
{
 @:     
}
else
{
 @:ViewBag.Name
}
like image 218
David W. Avatar asked Jul 19 '12 07:07

David W.


1 Answers

@(ViewBag.Name ?? Html.Raw(" "))
like image 98
VJAI Avatar answered Sep 26 '22 00:09

VJAI