views:

120

answers:

2

Hello, I am trying to convert an existing ASPX page to cshtml format.

The original ASPX looks something like this:

  <%
    if (!Model.ObjectList.Any())
    {

      %>
      <tr>
          <td>No data found</td>
      </tr>
      <%
     }

The equivalent Razor version looks like this:

@if (!Model.ObjectList.Any())
 {
 <tr>
   <td>No data found</td>
 </tr>
 }

While the original syntax works just fine, the equivalent fails with the following message

'System.Collections.Generic.List' does not contain a definition for 'Any'

I was wondering
a) why this is happening and
b) how to resolve this issue. I've added a reference to the System.LINQ namespace in my CSHTML file but to no avail.

Any help is much appreciated,

JP

A: 

You need to import the correct namespace:

using System.Linq;
jgauffin
As i mentioned in point b, i've already added this reference...
JP
+3  A: 

Thanks to everyone for their answers. This turned out to be an ID 10 T....

Essentially I neglected to strongly type my view. I was using

@inherits System.Web.Mvc.WebViewPage<dynamic>

instead of using

@inherits System.Web.Mvc.WebViewPage<MyViewModel>

Using the correct type fixed the issue. Thanks again, JP

JP