Getting a field value into a partial view using razor
Hello Umbracians.
I need a little guidance with a Partial View using MVC, Umbraco 6.1.6.
My documentType structure is as follows:
Master > SubMaster > Page
Page inherits a property from SubMaster called "pageHeroImage" of type Media Picker.
I have a Partial View that renders on Pages Template (Code Below) and I need to know how to get the field values. I know I can get it via @Umbraco.Content(id) and have been successful, but I want to use this partial view on other pages as well and I do not want to have to create new partial views for each Template I create.
I think your approach is fine. However if you did want to make you partial view really flexible you could pass the model into it. However normally when you do this you need to use the strongly typed model (Model.Content) instead of dynamics (CurrentPage) but you can work around this as shown below (not widely tested).
I like your approach better, but it rendered the following error:
The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'Umbraco.Core.Models.IPublishedContent'.
Getting a field value into a partial view using razor
Hello Umbracians.
I need a little guidance with a Partial View using MVC, Umbraco 6.1.6.
My documentType structure is as follows:
Master > SubMaster > Page
Page inherits a property from SubMaster called "pageHeroImage" of type Media Picker.
I have a Partial View that renders on Pages Template (Code Below) and I need to know how to get the field values. I know I can get it via @Umbraco.Content(id) and have been successful, but I want to use this partial view on other pages as well and I do not want to have to create new partial views for each Template I create.
Is there a way I can get this value?
This is my working code:
Any help would be greatly appreciated.
Phillip
Ok, so I added this code and got the result I needed as long as the Page is at the 2nd level (which it should be)
So the question now is... is there a better way?
Thanks
Phillip
Hi Phillip,
I think your approach is fine. However if you did want to make you partial view really flexible you could pass the model into it. However normally when you do this you need to use the strongly typed model (
Model.Content
) instead of dynamics (CurrentPage
) but you can work around this as shown below (not widely tested).MyPartial.cshtml
MyView.cshtml
Or if you really want to keep everything Dynamic:
Jeavon
Hi Jeavon.
I like your approach better, but it rendered the following error:
Hi Phillip,
Which code snippet did you use in your view? The
@Html.Partial
bitJeavon
Im sorry! I opted for the first
Hold on... Duh! I didn't pass the page when rendering the view. Standby!!!
I'm having this problem too.
solution page?
is working on a reply...