Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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!!
Hi Nathan,
Yes this is possible. You can either do it as standard MVC. https://stackoverflow.com/questions/20799658/how-can-i-pass-parameters-to-a-partial-view-in-mvc-4
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.
Regards
David
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 : https://www.umbrajobs.com/blog/posts/2020/july/passing-objects-into-a-partial-view-with-umbraco-8/
It sounds like you are on the right track.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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!!
Hi Nathan,
Yes this is possible. You can either do it as standard MVC. https://stackoverflow.com/questions/20799658/how-can-i-pass-parameters-to-a-partial-view-in-mvc-4
For Umbraco what I do is.
Change the inherits line at the top on your partial view from its default
to Something like either of these depending on what you want to do.
Then in your view page you can call the partial view liek this.
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.
Then your view might look something like this.
Hope this helps.
Regards
David
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 : https://www.umbrajobs.com/blog/posts/2020/july/passing-objects-into-a-partial-view-with-umbraco-8/
It sounds like you are on the right track.
is working on a reply...