I am trying to show the viewbag items in a carousal. Inside foreach how do I check each list item in viewBag is null or not null before assigning the value to imgSrc.
@{
var first = true;
foreach (var item in ViewBag.carousel)
`enter code here` {
string filepath = System.Configuration.ConfigurationManager.AppSettings["Carousal"].ToString();
var imgSrc = "";
if (item!= "0")
{
imgSrc = filepath + item;
}
else
{
imgSrc = filepath + "DefaultProduct.Jpg";
}
<div class="carousel-item @(first?Html.Raw("active"):Html.Raw(""))">
<img class="d-block w-100" src="imgSrc" alt="">
</div>
first = false;
}