Copied to clipboard

Flag this post as spam?

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


  • Koen Defrancq 14 posts 35 karma points
    Nov 14, 2012 @ 01:20
    Koen Defrancq
    0

    v4.10 Umbraco.TypedMedia problem in view

    In a 4.10 project I'm playing with views and partial views but i have a weird issue

    I'm trying to get all files from a media folder

    Media folder is like this :

    Media
    --V2
    ----HeaderImages
    ------General [id 1]
    --------Picture1 
    --------Picture2
    ------Project1 [id 2]
    ------Project2 [id 3]

    When I try to loop the images under general (id:1) with the following code

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    @{
    var startMedia = Umbraco.TypedMedia(1); 
    }
    @foreach(var mfile in startMedia.Children()){ var mediaName = mfile.GetPropertyValue("umbracoFile"); <p>@mfile.Id : @mfile.Name : @mediaName</p> }

    It gives me

    1 : General :
    2 : Project1 :
    3 : Project2 :

    With TypedContent Im not getting this behavior, there I get the children not the siblings

    And even weirder when I change Children() to Descendants() IIS crashes.

    This is on a local dev machine.
    This site is running live on4.7 i took a copy to local machine to make some changes and upgrade everything local before doing it on live site.
    I upgraded gradually to 4.9 and have been updating everything to Razor macros and everythng works fine.
    With 4.10 I decided to play with views and maybe make the switch completely to mvc.

    All razor macros still work with 4.10 everything works.

    This was the first macro i tried to convert to a partial view (it generates some js to have some slideshow in header) The razor macro works perfect it gets the images with children from the startmedia.

    Anyone have a clue what I am doing wrong?

    Is there already an documentation to find?

  • Koen Defrancq 14 posts 35 karma points
    Nov 14, 2012 @ 13:48
    Koen Defrancq
    0

    Same happens on a clean install of 4.10
    i just create a simple document type with razor template

    in the template I get a TypedMedia of a media folder with 3 images when doing getting the children i get the children of the parent.

    trying to get Descendants will crash IIS also

    Should i get a mediafolder in a different way?

  • Koen Defrancq 14 posts 35 karma points
    Nov 14, 2012 @ 17:01
    Koen Defrancq
    0

    Ended up finding a solution dont know if it is best practice but it works for now : 

    @using umbraco.cms.businesslogic.media
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    @{
    var startMedia = new Media(1118);
    }
    @foreach (var mfile in startMedia.Children){ 
    <p>@mfile.Id : @mfile.GetImageUrl()</p>
    }

  • Koen Defrancq 14 posts 35 karma points
    Nov 14, 2012 @ 20:45
    Koen Defrancq
    0

    Not I good solution since calls to db happen in new scenario (see : http://issues.umbraco.org/issue/U4-1174)

    so for now i will use rendermacro

    follow up the problem here : http://issues.umbraco.org/issue/U4-1202

Please Sign in or register to post replies

Write your reply to:

Draft