В моей 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>
В настоящее время, однако, когда я нажимаю кнопку, мой соответствующий Action Controller (DuesPaidMember()
) называется , но когда линия 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] `
У кого-нибудь есть мысли о том, что я, по-видимому, делаю неправильно?