홈 페이지 (색인)에 최근 컨텍스트를 표시 할 수있는 부분보기를 생성하려고합니다. 그러나 모델은 NULL로만 반환됩니다.다른 컨트롤러에서 부분보기 표시
팟 캐스트 제어 방법 :
// Generates list of most recent 2 podcasts
public async Task<IActionResult> _RecentPodcasts()
{
var recentList = from p in _context.Podcast
select p;
recentList = recentList.OrderByDescending(p => p.PublishDate).Take(2);
return View(await recentList.ToListAsync());
}
부분보기 (포드 캐스트/_RecentPodcasts.cshtml)
@model IEnumerable<ComesNaturally.Models.Podcast>
@{
ViewData["Title"] = "_RecentPodcasts";
}
<div class="col-md-6">
<div class="table-title">
<table class="table-fill">
<thead>
<tr>
<th>Recent Podcasts</th>
</tr>
</thead>
@if (Model == null)
{
<tr> No items found</tr>}
else
{
@foreach (var item in Model)
{
<tr>
<td><a asp-action="Details" asp-route-id="@item.ID" class="alert-link">@Html.DisplayFor(modelItem => item.Title)</a></td>
</tr>
}}
</table>
</div>
</div>
홈페이지보기 (홈/Index.cshtml)
@Html.Partial("~/Views/Podcasts/_RecentPodcasts.cshtml");
모델은 기본보기의 모델과 부분보기의 모델이 같습니까? 그렇지 않다면'Partial' 문에서 부분 뷰의 매개 변수로 모델을 전달하려고 했습니까? (또는 표현입니까?) – Gilles