Copied to clipboard

Flag this post as spam?

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


  • Mads Pedersen 1 post 31 karma points
    Oct 08, 2013 @ 11:41
    Mads Pedersen
    0

    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

  • SkyAngel 4 posts 24 karma points
    Oct 08, 2013 @ 11:51
    SkyAngel
    0

    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

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 08, 2013 @ 12:10
    Jeroen Breuer
    102

    You need to make sure that your custom model inherits from the Umbraco RenderModel. This is also done in the Hybrid Framework.

    Jeroen

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 08, 2013 @ 12:24
    Jeavon Leopold
    1

    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 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

    Jeavon

  • fabrice 104 posts 227 karma points
    Oct 09, 2013 @ 09:15
    fabrice
    1

    Woow this Hybric Mvc Framework project is amazing !!! It's exactly what we were trying to do !

    Thank you very much Jeroen !

  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    Aug 04, 2015 @ 08:05
Please Sign in or register to post replies

Write your reply to:

Draft