Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Martin McMahon 69 posts 101 karma points
    Jan 13, 2016 @ 12:40
    Martin McMahon
    0

    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?

  • TheOriginal 22 posts 122 karma points
    Jan 13, 2016 @ 13:20
    TheOriginal
    0

    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.

  • Martin McMahon 69 posts 101 karma points
    Jan 13, 2016 @ 14:22
    Martin McMahon
    0

    Thanks, but it was the creation of the partial view that was the issue.

  • Graeme W 113 posts 289 karma points
    Jan 13, 2016 @ 13:47
    Graeme W
    100

    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

    @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>&nbsp;
    
                <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

      @Html.Partial("NewsMini") 
    
  • Martin McMahon 69 posts 101 karma points
    Jan 13, 2016 @ 14:23
    Martin McMahon
    0

    Fantastic, many thanks.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies