I replaced this:
.OrderBy(p =>
{
if (p.Office == "President")
return 0;
else if (p.Office == "Vice-President")
return 1;
else if (p.Office == "Secretary-Treasurer")
return 2;
}).ToListAsync();
with this:
.OrderBy(p => p.Office == "President" ? 0 : p.Office == "Vice-President" ? 1 : p.Office == "Secretary-Treasurer" ? 2 : 3).ToListAsync();
I’m hoping it is useful to someone. Never saw this solution anywhere else.
1
solved Razor Page .NET Core 2.2 If + ElseIf statement doesn’t work in Lambda expression [duplicate]