I am trying to generate a partial view that will allow me to display recent context on the home page (Index). However, the model is only returning as NULL.
Podcast controller method:
// 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());
}
Partial view (Podcasts/_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>
Main view (Home/Index.cshtml)
@Html.Partial("~/Views/Podcasts/_RecentPodcasts.cshtml");