[英]If list returns empty display message
Using MVC I am passing a Projects
list to the view. 使用MVC我将一个
Projects
列表传递给视图。
@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: Model.Projects.Count> 0说:
operator > cant be applied to operands of type 'method group' and 'int'
operator>无法应用于'method group'和'int'类型的操作数
how about 怎么样
Model.Projects.Count() > 0
or 要么
Model.Projects.Any()
if you are using resharper, it will recommend you for Model.Projects.Any() 如果你使用resharper,它会推荐你使用Model.Projects.Any()
You are treating Count
as if it were a property. 您将
Count
视为属于财产。
It's a method. 这是一种方法。 You need to call
Count()
. 你需要调用
Count()
。 Eg 例如
@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>
}
Count is a method. 伯爵是一种方法。 Your code must be
你的代码必须是
Model.Projects.Count()
You are missing the brackets after Count. 您在Count之后缺少括号。
Count()
is a method not a property, so your code should be: Count()
是一个方法而不是属性,所以你的代码应该是:
@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
是否有任何元素,而不是有多少元素,而不是
Model.Projects.Count() > 0
you could use 你可以用
Model.Projects.Any()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.