Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Mvc Linq搜索没有';不在列表中显示外键_C#_Asp.net Mvc_Linq - Fatal编程技术网

C# Mvc 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.

我正在尝试使用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.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>