0
我有MVC應用程序,我有兩個實體。LINQ查詢不能正常工作
實體引線從客戶繼承。
現在,在鉛控制器指數來看,我已經寫了下面的代碼...
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>
感謝您的回覆,我更新了我的問題。我已添加完整視圖代碼。請檢查。 – user1668543
視圖看起來不錯。你能編寫一個集成測試來驗證你是否得到了該查詢的結果嗎?或者在Index視圖中放置一個斷點來查看返回的內容。現在看起來好像沒有線索。 – dove