Copied to clipboard

Flag this post as spam?

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

  • Nathan Reece 28 posts 199 karma points
    4 days ago
    Nathan Reece

    Can i pass Values into my Umbraco 8 Partial Views

    Is it possible to pass objects into partial views, If so can anyone help me out.

    I have a list of featured staff profiles saved on my home page and i want access to them in my partial view.

    Please can someone help!!

  • David Armitage 314 posts 1239 karma points
    4 days ago
    David Armitage

    Hi Nathan,

    Yes this is possible. You can either do it as standard MVC.

    For Umbraco what I do is.

    Change the inherits line at the top on your partial view from its default

    @inherits Umbraco.Web.Mvc.UmbracoViewPage

    to Something like either of these depending on what you want to do.

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<string>
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<int>
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<YourClass>

    Then in your view page you can call the partial view liek this.

    @Html.Partial("~/views/partials/yourPartial.cshtml", YourObjectHere)

    So going off your description if your are handling featured staff profiles I assume you are dealing with a list of IPublishedContent.

    Your partial should look something like this.

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IEnumerable<IPublishedContent>>

    Then your view might look something like this.

    @Html.Partial("~/views/partials/staffProfiles.cshtml", Model.FeaturedStaffProfiles)

    Hope this helps.



  • Nathan Reece 28 posts 199 karma points
    3 days ago
    Nathan Reece

    Thanks Dave, I still dont understand it 100% but i now have my Data passed in and displayed how i intended.

    I have wrote a quick blog to help anyone else with the same issues as i had, Here is a link to my Blog :

  • David Armitage 314 posts 1239 karma points
    3 days ago
    David Armitage

    It sounds like you are on the right track.

Please Sign in or register to post replies

Write your reply to: