Riquelmy Melara
Riquelmy Melara

Reputation: 941

Empty Model Object

So I have this code

@if (Model.Products != null)
{

  @Html.Raw(string.Join(", ", Model.Products.Select(s => string.Format("<span>{0}</span>", s.Name))))

}
else
{
  <text>N/A</text>
}

Which prints a list of products separated by a comma, but the problem is that the Model.Products is never null, it can contain cero products but its never null, is there another way to compare this If statement?

Upvotes: 1

Views: 226

Answers (1)

CassOnMars
CassOnMars

Reputation: 6181

If it is never null, you can use

@if (Model.Products.Any())

Upvotes: 2

Related Questions