Reputation: 3945
Using MVC I am passing a Projects
list to the view.
@if (Model.Projects != null && Model.Projects.Count > 0)
{
<fieldset>
<table class="items" summary="@T("This is a table of the delivery Runs in your application")">
<colgroup>
}
else
{
//no data available
}
Model.Projects.Count > 0 is saying:
operator > cant be applied to operands of type 'method group' and 'int'
Upvotes: 4
Views: 1137
Reputation: 2780
You are missing the brackets after Count. Count()
is a method not a property, so your code should be:
@if (Model.Projects != null && Model.Projects.Count() > 0)
{
<fieldset>
<table class="items" summary="@T("This is a table of the delivery Runs in your application")">
<colgroup>
}
but seeing as you are only concerned with whether there are any elements in Model.Projects
, not how many there are, instead of
Model.Projects.Count() > 0
you could use
Model.Projects.Any()
Upvotes: 1
Reputation: 14618
You are treating Count
as if it were a property.
It's a method. You need to call Count()
. E.g.
@if (Model.Projects != null && Model.Projects.Count() > 0)
{
<fieldset>
<table class="items" summary="@T("This is a table of the delivery Runs in your application")">
<colgroup>
}
Upvotes: 3
Reputation: 3746
how about
Model.Projects.Count() > 0
or
Model.Projects.Any()
if you are using resharper, it will recommend you for Model.Projects.Any()
Upvotes: 5