LINQ in MVC Razor View

10,665

Try this:

@{
    IEnumerable<AERS_WEB.Models.clsFileDetails> fls =
        Model.FILES.Where(q=>q.DEVELOPER=="ac").ToList();
 }

Although it seems that AERS_WEB.Models.clsFileDetails is not a type.

Try to think of it like:

IEnumerable<int> = new List<int>();

or

IEnumerable<SomeClass> = new List<SomeClass>();

By the way, keep in mind that it's bad habbit to query a database from a view, it disturbs the MVC pattern.

And make sure that Model.FILES.Where(q=>q.DEVELOPER=="ac") returns items of type: AERS_WEB.Models.clsFileDetails.

Share:
10,665
Admin
Author by

Admin

Updated on June 30, 2022

Comments

  • Admin
    Admin almost 2 years

    I have written a working MVC web app. I started using SQL statements back to the DB, but have changed to LINQ. I have a view that shows all work in the IT department and a button to allow the user to select tasks allocated to them.

    I am trying to get the IT workers list from the model list of files, like this

    {@IEnumerable<@AERS_WEB.Models.clsFileDetails> fls = @Model.FILES.Where(q=>q.DEVELOPER=="ac")}
    

    but I get an error

    Using the generic type 'System.Collections.Generic.IEnumerable' requires 1 type arguments

    I've also tried

    {@List<@AERS_WEB.Models.clsFileDetails> fls = @Model.FILES.Where(q=>q.DEVELOPER=="ac")}
    {@IList<@AERS_WEB.Models.clsFileDetails> fls = @Model.FILES.Where(q=>q.DEVELOPER=="ac")}