I am working on an MVC, which displays a list of requests to a user. The model looks something like this:
public class RequestModel
{
public string Status { get; set; }
}
And the controller looks something like this:
public ActionResult Index()
{
return View(db.Requests.ToList());
}
I would like the index view page to show a list of the requests with status "Pending", which I have attempted with the following code:
<table class="table">
@foreach (var item in Model)
{
<tr>
<td>
@if (modelItem => item.Status == "Pending")
{
@Html.DisplayFor(modelItem => item.Status)
}
</td>
</tr>
}
</table>
However, this gives me the following error:
Cannot convert lambda expression to type "bool" because it is not a delegate type.
I am unsure what this errors means and how to work around it. If anyone has any help or advice I would greatly appreciate it.
Your condition should look like:
@if (item.Status == "Pending")
You're trying to use lambda expression (modelItem => item.Status == "Pending") where you should use simple condition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With