我需要帮助以确保我的 razor 页面上此代码的语法正确:
@foreach (var officerGroup in Model.Results
.Where(i => i.InvestType in ("YO", "CRD", "PPI", "PSI")
.GroupBy(x => x.ProbOfficer))
基本上,我想按报告的此特定部分中的特定子集
InvestType
值进行过滤。我不希望包含 InvestType
的其他值。我不知道如何做“in”类型的陈述。
感谢您提供的任何帮助。
您可以使用
@{ ... }
在 .cshtml
文件中声明变量:
@{
var fullReportList = new List<string> { "CRD", "PPI", "PSI", "Supvsn Only", "TO" };
}
@foreach (var officerGroup in Model.Results
.Where(i => fullReportList.Contains(i.InvestType))
.GroupBy(x => x.ProbOfficer))
{
}
或者您可以将其添加到您的
PageModel
中,如下所示:
public class DemoModel : PageModel
{
public List<string> FullReportList => new() { "CRD", "PPI", "PSI", "Supvsn Only", "TO" };
public void OnGet()
{
//...
}
}
并在
.cshtml
:
@foreach (var officerGroup in Model.Results
.Where(i => Model.FullReportList.Contains(i.InvestType))
.GroupBy(x => x.ProbOfficer))
{
}