This is something that Jeroen thought about for the Hybrid Mvc Framework project and is what leads to it being called "Hybrid". Essentially, you need to have your Model extend the RenderModel, then you can access it normally, .e.g @Model.Content.x Have a look at this BaseModel
As an alternative, and as you do have access to the Umbraco helper within your partial view, I think you can also do something like var myprop = Umbraco.AssignedContentItem.GetPropertyValue<string>("myprop"); but I think that is only available in v6.1.5 or later
MVC : how to use a custom model and access CurrentPage in a Partial View
Hello,
We are using Umbraco 6.1.5 MVC.
We have a normal Umbraco view that calling a Partial View with @Html.Action
The controller of the partial view return to the partil view giving a custom model (like in http://24days.in/umbraco/2012/creating-a-login-form-with-umbraco-mvc-surfacecontroller)
How can we access the Current Page (or Model.Content) from the Partial View ?
We try to inherit the partial view to :
@inherits Umbraco.Web.Mvc.UmbracoViewPage<MyCustomModel>
instead of doing @model MyCustomModel
But then we still don't know how to access the current umbraco page.
Many thanks,
Mads
I found the same issue some days ago. If you want to get a field you created in document I just do this in your razor file:
Model.Content.GetPropertyValue("yourfield")
Of course you need your model to inherit from RenderModel first.
Hope it helps
You need to make sure that your custom model inherits from the Umbraco RenderModel. This is also done in the Hybrid Framework.
Jeroen
Hi Mads,
This is something that Jeroen thought about for the Hybrid Mvc Framework project and is what leads to it being called "Hybrid". Essentially, you need to have your Model extend the RenderModel, then you can access it normally, .e.g
@Model.Content.x
Have a look at this BaseModelAs an alternative, and as you do have access to the Umbraco helper within your partial view, I think you can also do something like
var myprop = Umbraco.AssignedContentItem.GetPropertyValue<string>("myprop");
but I think that is only available in v6.1.5 or laterJeavon
Woow this Hybric Mvc Framework project is amazing !!! It's exactly what we were trying to do !
Thank you very much Jeroen !
Try this https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/68071-accessing-currentpage-properties-in-a-partial-which-is-using-a-custom-model
is working on a reply...