我是MVC的新手,不确定如何解决此错误。我需要根据通过参数传递的ID列出项目详细信息。有没有其他写方法,可以使我看不到标题中的错误?
.ToListAsync(d => d.ItemDetailId == id)
控制器
public async Task<IActionResult> Details(int? id)
{
if (id == null)
{
return NotFound(); }
var itemDetail = await _context.ItemDetail
.Include(i => i.MenuItem)
.ToListAsync(d => d.ItemDetailId == id);
if (itemDetail == null)
{
return NotFound();
}
return View(itemDetail);
}
接收详细信息操作视图
@model Farbucks.Models.ItemDetail
@{
ViewData["Title"] = "Details";
}
<h2>Details</h2>
<div>
<h4>ItemDetail</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Size)
</dt>
<dd>
@Html.DisplayFor(model => model.Size)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Price)
</dt>
<dd>
@Html.DisplayFor(model => model.Price)
</dd>
<dt>
@Html.DisplayNameFor(model => model.MenuItem)
</dt>
<dd>
@Html.DisplayFor(model => model.MenuItem.Name)
</dd>
</dl>
</div>
<div>
<a asp-controller="MenuItems" asp-action="Index">Back to List</a>
</div>