在我MVC5應用程序,我目前正在處理2個表:顯示已付每年會費的MemberOrg列表?
[MemberDues] -- [Id], [Year], [Display], [Amount]
[MemberDuesReceived] -- [Id], [MemberDuesId], [MemberOrgId], [PaidByUserId], [TransactionId], [Paid], [DatePaid], [PaymentMethod], [PayPalPaymentId], [PayPalPayerId], [PayPalPaymentState]
我有一個觀點(見下文),我顯示不同[MemberDues]
記錄:
@model IEnumerable<PROJECTdev.Models.MemberDues>
<script type="text/javascript" src="~/Areas/Admin/Scripts/Dues/Index.min.js"></script>
<div id="alert" style="display: none;"></div>
<table class="table table-striped">
<thead>
<tr>
<th class="col-md-2">
</th>
<th>
@Html.DisplayNameFor(model => model.Year)
</th>
<th>
@Html.DisplayNameFor(model => model.Display)
</th>
<th>
@Html.DisplayNameFor(model => model.Amount)
</th>
<th>View</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
<a href="MemberDuesManage/Edit/@item.Id" class="btn btn-success btn-sm noDecoration"><span class="glyphicon glyphicon-pencil"></span> Edit</a>
<a href="MemberDuesManage/Delete/@item.Id" class="btn btn-default btn-sm noDecoration"><span class="glyphicon glyphicon-floppy-remove"></span> Delete</a>
</td>
<td>
@Html.DisplayFor(modelItem => item.Year)
</td>
<td>
@Html.EditorFor(modelItem => item.Display, new { htmlAttributes = new { @class = "form-control pull-left", style = "height: 20px; width: 20px;", onclick = "disableEnableDues(" + item.Id + ", this)" } })
</td>
<td>
@Html.DisplayFor(modelItem => item.Amount)
</td>
<td>
<a href="~/Admin/MemberDuesManage/DuesPaidMembers/@item.Id" class="btn btn-default btn-sm noDecoration"><span class="glyphicon glyphicon-list-alt"></span> Paid</a>
</td>
</tr>
}
</tbody>
</table>
什麼,我試圖do有,當點擊[Paid]按鈕(鏈接)時,會出現一個列出所有已付會費的會員組織的視圖。爲此,我必須查詢[MemberDuesReceived]
以獲得合適的[MemberDuesId]
,並返回所有匹配的記錄[MemberDuesId]
& [Paid] == true
。這是我曾嘗試以下:
public async Task<ActionResult> DuesPaidMembers(int id)
{
MemberDues memberDues = await db.MemberDues.FindAsync(id);
return View(db.MemberDuesReceived.Where(mdr => mdr.MemberDuesId == memberDues.Id && mdr.Paid).ToListAsync());
}
然後,我創建了一個名爲DuesPaidMembers.cshtml
視圖,低於:
@model IEnumerable<PROJECTdev.Models.MemberDuesReceived>
@{
ViewBag.Title = "DuesPaidMembers";
Layout = "~/Areas/Admin/Views/Shared/_LayoutAdmin.cshtml";
}
<h2>DuesPaidMembers</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.MemberDues.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.MemberOrganization.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.PaidByUser.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.TransactionId)
</th>
<th>
@Html.DisplayNameFor(model => model.Paid)
</th>
<th>
@Html.DisplayNameFor(model => model.DatePaid)
</th>
<th>
@Html.DisplayNameFor(model => model.PaymentMethod)
</th>
<th>
@Html.DisplayNameFor(model => model.PayPalPaymentId)
</th>
<th>
@Html.DisplayNameFor(model => model.PayPalPayerId)
</th>
<th>
@Html.DisplayNameFor(model => model.PayPalPaymentState)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.MemberDues.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.MemberOrganization.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.PaidByUser.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.TransactionId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Paid)
</td>
<td>
@Html.DisplayFor(modelItem => item.DatePaid)
</td>
<td>
@Html.DisplayFor(modelItem => item.PaymentMethod)
</td>
<td>
@Html.DisplayFor(modelItem => item.PayPalPaymentId)
</td>
<td>
@Html.DisplayFor(modelItem => item.PayPalPayerId)
</td>
<td>
@Html.DisplayFor(modelItem => item.PayPalPaymentState)
</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>
目前然而,當我按一下按鈕,我適當的控制器動作()被稱爲,但是當線路return View(db.MemberDuesReceived.Where(mdr => mdr.MemberDuesId == memberDues.Id && mdr.Paid).ToListAsync());
被命中,我收到以下錯誤:
The model item passed into the dictionary is of type 'System.Threading.Tasks.Task
1 [System.Collections.Generic.List 1[PRISMdev.Models.MemberDuesReceived]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [PRISMdev.Models.MemberDuesReceived]」`
有沒有人有什麼想法,我顯然做錯了?