Copied to clipboard

Flag this post as spam?

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


  • Vlad 4 posts 94 karma points
    Dec 08, 2015 @ 05:15
    Vlad
    0

    Partial view to display list of objects on every page

    First of all I'd like to say - I'm new to Umbraco. I watched instructional videos, read docuemntation but still can't figure this one out.

    So I have a Person object with some basic properties - name, image, title etc. There will be a page for each person. And also I'd like to display a gallery of persons on every other page - Home, about, etc.

    If I'm building pure MVC site I'll create a partial view with a controller that will use IPersonService to get all that data from DB for example. And in my partial view I'll use something like this as a model:

    public class PersonListViewModel
    {
        public IEnumerable<Person> { get; set; }
    }
    

    How to do this "the Umbraco way"?

    Thanks V.

  • Maria 34 posts 128 karma points
    Dec 08, 2015 @ 10:33
    Maria
    100

    When you say that there will be a page, do you mean a node in Umbraco? If yes, then what you can do is:

    1. For the person page In the pages template simply display properties from Umbraco (using for example Model.Content.GetPropertyValue("name")).

    2. For the gallery of persons

    On the gallery template make a call to your controller.

    Create a controller that gets the list of person objects from Umbraco (using content service https://our.umbraco.org/documentation/reference/management/services/contentservice).

    The controller should return a partial view with the list as a model.

    In your partial view declare the model and iterate through the list of persons displaying the properties you would like to show.

    Ex.

    @model List<Person>
    <div>
         @foreach (Person person in Model)
        {
               <p>@person.name</p>
        }
    </div>
    
Please Sign in or register to post replies

Write your reply to:

Draft