Skip to the content

Passing Objects into a Partial View with Umbraco 8

So lets just jump straight into it, There are many reason why you may want to pass a Object into your Partial views and I am not going to get into all those right now maybe in an Umbraco 8 Blog article in the future. 

Its really easy to pass property into partial view, you could pass anything you can pass a string a int a content item pretty much anything you like, As a quick example i just passed a staff profile into my partial view.

Here is a code snippet of my partial view.

@inherits UmbracoViewPage<Playground.Core.Models.StaffProfile>
<div class="staff-profile col-md-4">
<h2 class="yellow">@Model.StaffFirst</h2>
<p>Job Title</p>

Now here is a snippet of my Home page where i have displayed my Staff Profiles.

 <div class="col-md-12">
<h3>Featured Staff</h3>
<div class="row">
@foreach (StaffProfile staffProfile in Model.FeaturedStaff.OfType<StaffProfile>())
@Html.Partial("~/Views/Partials/staffProfile.cshtml", staffProfile)

Its as simple as that.

About the author

Nathan Reece

.Net MVC Developer | Umbraco Novice

Hey Guys,

I'm an New Developer with a passion for coding. I absolutely love working with Umbraco CMS and appreciate the Umbraco community even more.

I've got 3 years+ .Net experience and 5 years+ experience working in the Web Develepment industry, both coding and marketing job websites. I wanted to use my skills to help give something back to this awesome community and seems like the right place to do just that.

Follow me on social media

If you're an Umbraco professional, partner, employer, recruiter or a passionate Umbraco community builder then I'm more than happy to hear from you. Follow me on my social media channels and please reach out if you have any needs, want help or consultation with anything Umbraco related or just want a general chat.

comments powered by Disqus

Blog Filter

How we can help?

Need help with an Umbraco project?

Need help with a project but not too sure who to approach? Send us your project brief and budget. We will provide a free consultation and can help you gather quotes from the best and most suitable freelancers or agencies.

Looking to hire an Umbraco Professional?

Have you got job vacancy and want to hire an Umbraco professional? Post a job on our website for free. Alternatively let us know your requirements and we will send suitable prospects your way.

Claim your free profile!

Are you an Umbraco Freelance Developer or Umbraco partner that wants to advertise on our site? If you work with Umbraco or registered as an Umbraco partner then you can create a profile for free.

Let's build the Umbraco Community

We're big on building the Umbraco community and we think you guys are awesome! If there's anyway at all we can help then please reach out.