0

我有 MVC 应用程序,我有两个实体。

实体线索继承自客户。

在此处输入图像描述

现在,在 Lead 控制器索引视图中,我编写了以下代码...

public ViewResult Index()

       {     

           var Leads = (from c in db.Customers.OfType<CRMEntities.Lead>()
                        where(c.IsActive == true) select c);

            return View(Leads.ToList());

        }

我在索引视图中有下面的代码。

@model IEnumerable<CRMEntities.Lead>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
.
.

记录存在于表中,它不返回任何记录。查询对吗?

完整查看代码

@model PagedList.IPagedList<CRMEntities.Lead>


@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            Status
        </th>
        <th>
            IsQualified
        </th>
        <th>
            Name
        </th>
        <th>
            Address
        </th>
        <th>
            OfficePhone1
        </th>
        <th>
            Website
        </th>
        <th>
            Email2
        </th>
        <th>
            Email1
        </th>
        <th>
            FaxNo
        </th>
        <th>
            Remark
        </th>
        <th>
            Rating
        </th>
        <th>
            BusinessType
        </th>
        <th>
            IsActive
        </th>

    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Status)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.IsQualified)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Address)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.OfficePhone1)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Website)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Email2)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Email1)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.FaxNo)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Remark)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Rating)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.BusinessType)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.IsActive)
        </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>
}

</table>
4

1 回答 1

0

从可以看到的内容来看,查询看起来不错。

您显示的视图代码不会显示任何内容。在视图中写出@Model.Count() 以查看您有多少条记录。

如果您没有数据库分析器,我建议您购买一个。

于 2012-09-29T11:19:36.670 回答