Copied to clipboard

Flag this post as spam?

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


  • Karen Worth 47 posts 140 karma points
    May 11, 2017 @ 10:54
    Karen Worth
    1

    new issue since upgrading to 7.6.1

    I was successfully displaying a block of 8 images on the main page of a site using media picker and the following script:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage @if (CurrentPage.HasValue("hpImageLinks")) { var hpImageLinksImagesList = CurrentPage.hpImageLinks.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); var hpImageLinksImagesCollection = Umbraco.Media(hpImageLinksImagesList); foreach (var hpItem in hpImageLinksImagesCollection) { var itemLink = hpItem.GetPropertyValue("link");

        <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
            <a class="mainImg" href="@itemLink"><img src="@hpItem.Url" /></a>
        </div>
    
    }
    

    } This was working nicely, until I upgraded to the latest umbraco release, now when I try running the site I get the following error:

    'Umbraco.Core.Models.PublishedContent.PublishedContentEnumerable' does not contain a definition for 'Split' Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Core.Models.PublishedContent.PublishedContentEnumerable' does not contain a definition for 'Split'

    Source Error:

    Line 2: @if (CurrentPage.HasValue("hpImageLinks")) Line 3: { Line 4: var hpImageLinksImagesList = CurrentPage.hpImageLinks.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); Line 5: var hpImageLinksImagesCollection = Umbraco.Media(hpImageLinksImagesList); Line 6: foreach (var hpItem in hpImageLinksImagesCollection)

    Unfortunately, this means that I cannot upgrade this site until I have a solution, any help would be gratefully received. Thanks

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 11, 2017 @ 10:59
    Alex Skrypnyk
    0

    Hi Karen

    Umbraco changed GetPropertyValue method little bit, read more about breaking changes - https://our.umbraco.org/documentation/getting-started/setup/upgrading/760-breaking-changes#property-value-converters-u4-7318

    Your code should work if you will use these lines:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @if (Umbraco.AssignedContentItem.HasValue("hpImageLinks"))
    {
        var hpImageLinksImagesCollection = Umbraco.AssignedContentItem.GetPropertyValue<IEnumerable<IPublishedContent>>("hpImageLinks");
    
        foreach (var hpItem in hpImageLinksImagesCollection)
        {
            var itemLink = hpItem.GetPropertyValue("link");
    
            <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
                <a class="mainImg" href="@itemLink"><img src="@hpItem.Url" /></a>
            </div>
    
        }
    }
    

    Hope it will help

    Alex

  • Karen Worth 47 posts 140 karma points
    May 11, 2017 @ 11:13
    Karen Worth
    0

    Thanks Alex, I tried that but now I'm getting: Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1061: 'object' does not contain a definition for 'Split' and no extension method 'Split' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 3: @if (Umbraco.AssignedContentItem.HasValue("hpImageLinks")) Line 4: { Line 5: var hpImageLinksImagesList = Umbraco.AssignedContentItem.GetPropertyValue("hpImageLinks").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); Line 6: var hpImageLinksImagesCollection = Umbraco.TypedMedia(hpImageLinksImagesList); Line 7:

    I will see if I can fathom what is happening from reading through the information on the link you very kindly gave me. Thanks for your help. I do find it quite wearying when this sort of thing happens, I was just about to go live with this site, and split string seems like such a basic function that I could get to work time and again in any other form of code no matter what the upgrade status of the application is. But I am still quite new to umbraco, so .....

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 11, 2017 @ 11:14
    Alex Skrypnyk
    100

    Karen, try these lines:

    @if (Umbraco.AssignedContentItem.HasValue("hpImageLinks"))
    {
        var hpImageLinksImagesCollection = Umbraco.AssignedContentItem.GetPropertyValue<IEnumerable<IPublishedContent>>("hpImageLinks");
    
        foreach (var hpItem in hpImageLinksImagesCollection)
        {
            var itemLink = hpItem.GetPropertyValue("link");
    
            <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
                <a class="mainImg" href="@itemLink"><img src="@hpItem.Url" /></a>
            </div>
    
        }
    }
    
  • Karen Worth 47 posts 140 karma points
    May 11, 2017 @ 11:17
    Karen Worth
    0

    Alex you are a MEGASTAR. Thank you so much! I really appreciate your help and yes that now works fine! (phew)

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 11, 2017 @ 11:18
    Alex Skrypnyk
    0

    You are welcome, I'm really happy that we found out what was the problem.

    Have a nice day!

    Alex

  • Karen Worth 47 posts 140 karma points
    May 11, 2017 @ 11:22
    Karen Worth
    0

    Me too! and you have a fantastic day yourself X

Please Sign in or register to post replies

Write your reply to:

Draft