LINQ查询无法正常工作

时间:2012-09-29 06:43:57

标签: asp.net-mvc dynamics-crm

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

实体主管继承自客户。

enter image description here

现在,在Lead controllers索引视图中,我写了下面的代码......

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>

1 个答案:

答案 0 :(得分:0)

从可以看到的内容看起来很好。

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

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

相关问题