简体   繁体   English

LINQ in MVC Razor View

[英]LINQ in MVC Razor View

I have written a working MVC web app. 我写了一个有效的MVC网络应用程序。 I started using SQL statements back to the DB, but have changed to LINQ. 我开始将SQL语句重新用于DB,但已更改为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. 我有一个显示IT部门所有工作的视图和一个允许用户选择分配给他们的任务的按钮。

I am trying to get the IT workers list from the model list of files, like this 我试图从模型的文件列表中获取IT工作者列表,如下所示

{@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 使用泛型类型'System.Collections.Generic.IEnumerable'需要1个类型参数

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")}

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. 虽然看起来AERS_WEB.Models.clsFileDetails不是一个类型。

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. 顺便说一句,请记住,从视图中查询数据库是不好的习惯,它会扰乱MVC模式。

And make sure that Model.FILES.Where(q=>q.DEVELOPER=="ac") returns items of type: AERS_WEB.Models.clsFileDetails . 并确保Model.FILES.Where(q=>q.DEVELOPER=="ac")返回类型为AERS_WEB.Models.clsFileDetails项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM