If you want to check if a List is empty, try this:
@if( ((List<Furnitures>) Viewbag.itemlist).Count > 0)
{
//The string is displayed even tho it does not contain any data
<p>I appear</p>
}
or
@if( ((List<Furnitures>) Viewbag.itemlist).Any())
{
//The string is displayed even tho it does not contain any data
<p>I appear</p>
}
Update:
As pointed out by @learnprogramming, the second solution doesn't work.
.Any() doesn't operate on a List, it operates on an IEnumerable.
To make it works you need to add
@using System.Linq
to the top of your view file. Thanks to @ColinM for the tip.
Update 2
Another tip from @Colin.
MVC has full support for model binding between Controllers and Views.
It's way better to pass data with model binding instead of ViewBag.
In your ActionResult you should do this:
var furnituresList = db.Furnitures.Where(x => x.Status == 1).ToList();
return View(furnituresList);
Then in your view put this on top (after the @using directives):
@model List<Furnitures>
And then check with this:
@if(Model.Count > 0)
{
//The string is displayed even tho it does not contain any data
<p>I appear</p>
}