C# Mvc Linq搜索没有';不在列表中显示外键
我正在尝试使用linq搜索我的索引。搜索和一切工作,但它不显示我的外键名称 控制器:C# Mvc Linq搜索没有';不在列表中显示外键,c#,asp.net-mvc,linq,C#,Asp.net Mvc,Linq,我正在尝试使用linq搜索我的索引。搜索和一切工作,但它不显示我的外键名称 控制器: public ActionResult Index(string search) { var formular = from s in db.Formulars.Include(f => f.sagsbehandlere).Include(f => f.medlemmer) let mem = s.medlemmer.forNavn + " " + s.
public ActionResult Index(string search)
{
var formular = from s in db.Formulars.Include(f => f.sagsbehandlere).Include(f => f.medlemmer)
let mem = s.medlemmer.forNavn + " " + s.medlemmer.EfterNavn
let Sag = s.sagsbehandlere.forNavn + " " + s.sagsbehandlere.EfterNavn
where mem.Contains(search) || Sag.Contains(search)
select s;
return View(formular);
}
视图:
@使用(Html.BeginForm())
{
}
@DisplayNameFor(model=>model.sagsbehandler.forNavn)
@DisplayNameFor(model=>model.FormularNavn)
@DisplayNameFor(model=>model.behandled)
@DisplayNameFor(model=>model.MedlemmersId)
@foreach(模型中的var项目){
@Html.DisplayFor(modelItem=>item.sagsbehandler.forNavn)@Html.DisplayFor(modelItem=>item.sagsbehandler.EfterNavn)
@DisplayFor(modeleItem=>item.FormularNavn)
@DisplayFor(modelItem=>item.behandled)
@Html.DisplayFor(modelItem=>item.medlemmer.forNavn)@Html.DisplayFor(modelItem=>item.medlemmer.EfterNavn)
@ActionLink(“编辑”,“编辑”,新的{id=item.id})|
@ActionLink(“详细信息”,“详细信息”,新的{id=item.id})|
@ActionLink(“删除”,“删除”,新的{id=item.id})
但是当我在索引页面上搜索时,它不会显示包含的sagsbehandlere
向林致意您的视图中有什么?已编辑,以便您可以查看视图。我认为这是因为它没有将包含绑定到“var公式”。实现看起来是正确的,sagsbehandlere中是否有数据,公式集和sagsbehandlere是否正确地保存在数据库中?是的,sagsbehandlere和medlemmer都有数据。它只是不显示在视图中。@ChesterCobus
@using (Html.BeginForm())
{
<input type="text" name="search" />
<input type="submit" value="search" />
}
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.sagsbehandlere.forNavn)
</th>
<th>
@Html.DisplayNameFor(model => model.FormularNavn)
</th>
<th>
@Html.DisplayNameFor(model => model.behandled)
</th>
<th>
@Html.DisplayNameFor(model => model.MedlemmersId)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.sagsbehandlere.forNavn) @Html.DisplayFor(modelItem => item.sagsbehandlere.EfterNavn)
</td>
<td>
@Html.DisplayFor(modelItem => item.FormularNavn)
</td>
<td>
@Html.DisplayFor(modelItem => item.behandled)
</td>
<td>
@Html.DisplayFor(modelItem => item.medlemmer.forNavn) @Html.DisplayFor(modelItem => item.medlemmer.EfterNavn)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>