i have index view that contain several partial view
in each partial view i want to show latest item added to database
What I have tried:
i create several section in my main index and add partial to it
<section class="news">
<h1 class="tit">Last News</h1>
<section class="line"></section>
@Html.Partial("_NewsPartialView")
</section>
<section class="downloads">
<h1 class="tit">Last PC sofwtare </h1>
<section class="line"></section>
@Html.Partial("_LastSoftwarePartialView")
</section>
<section class="downloads">
<h1 class="tit">Last Android sofwtare </h1>
<section class="line"></section>
@Html.Partial("_LastAndroidSoftwarePartialView")
</section>
in controller i add several action method for each partial view
public PartialViewResult _NewsPartialView()
{
return PartialView(db.Newses.Take(5).ToList());
}
public PartialViewResult _LastSoftwarePartialView()
{
return PartialView(db.software.Take(5).ToList());
}
public PartialViewResult _LastAndroidSoftwarePartialView()
{
return PartialView(db.DroidSoftware.Take(5).ToList());
}
and here is one of my parital view
@model IEnumerable<Myapp.Models.News>
<section class="content-part">
@foreach (var item in Model)
{
<section class="newbook-content">
@Html.DisplayFor(modelItem => item.NewsTitle)
@Html.DisplayFor(modelItem => item.NewsSummery)
@Html.DisplayFor(modelItem => item.NewsPublishTime)
@Html.DisplayFor(modelItem => item.NewsBody)
@Html.ActionLink("Details", "Details", new { id = item.NewsId })
</section>
}
</section>
but i get System.NullReferenceException: Object reference not set to an instance of an object exception
also i dont want to use viewmodel
if there any way to call action method when each partial view rendered?