I have used the following code for exactly the same thing in Umbraco v6. I have a NewsArticle document type and the following partial view displays the latest 2 news articles on the home page
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
// Get root node:
var root = Model.Content.AncestorOrSelf();
// Get the 2 newest 'NewsArticle' pages
var nodes = root.Descendants("NewsArticle").OrderBy("ArticleDate desc").Take(2);
// Then Loop through the filtered nodes, displaying the properties
}
<table class="table table-striped table-condensed table-bordered">
<tbody>
@foreach (var node in nodes)
{
<tr>
<td>
<span class="label label-success">
@if (node.GetProperty("articleDate").HasValue())
{
@Convert.ToDateTime(node.GetPropertyValue("articleDate")).ToString("dd-MM-yy")
}
else
{
@node.CreateDate.ToString("dd-MM-yy")
}
</span>
<a href="@node.Url">@node.Name</a>
<p>
@node.GetPropertyValue("leadText")
</p>
</td>
</tr>
}
</tbody>
</table>
On my home page template/view the partial view is displayed as follows
Partial View on homepage
This is probably a very simple question but i can't find any info.
I have a News page but also want to display the news items on the homepage using a partial view. How do I pass the model into the partial view?
once you have created the partial view with the razor you wont, to add it to a page simply add the following to the page template:
@Html.PartialView("partialAlias")
This will render the partial view, also it shall apear where ever the statement above is to in the template.
Thanks, but it was the creation of the partial view that was the issue.
Hi Martin
I have used the following code for exactly the same thing in Umbraco v6. I have a NewsArticle document type and the following partial view displays the latest 2 news articles on the home page
On my home page template/view the partial view is displayed as follows
Fantastic, many thanks.
is working on a reply...