Copied to clipboard

Flag this post as spam?

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


  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Dec 21, 2016 @ 14:50
    Jeroen Breuer
    0

    Grid rendering different after upgrade from 7.2 to 7.5

    Hello,

    I've upgraded an Umbraco project from 7.2 to 7.5. The Grid in the backoffice works fine after some tweaks, but the rendering in the frontend is different. In one of our grid views we do the following:

    var id = random.Next(10, 10000000);
    

    This id is used to give some divs a unique value and also to load some images inside the div. After the upgrade I noticed that some of the divs have the same id. Is there some new caching? I know since 7.3 there is a GridValueConverter: http://issues.umbraco.org/issue/U4-6148#comment=67-21169. Maybe it's related to that.

    Also some of the blocks don't render at random. Not sure what could cause that. Anyone seen this before?

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Dec 21, 2016 @ 15:09
    Jeroen Breuer
    0

    Most blocks are a LeBlenderModel. Maybe that also works different.

    Jeroen

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Dec 21, 2016 @ 16:10
    Anders Bjerner
    100

    I think the views are pretty much the same for rendering the grid, but I can say for sure that something hasn't changed.

    One thing that I know has changed: MVC

    Perhaps MVC does something differently?

    Anyways, how do you initialize random? In a view for each control? The reason that I'm asking is that two different instances of Random will generate the same number (since they're using the same seed if you don't specify one manually).

    For instance the following example:

    @{
        <pre>@(new Random().Next(10, 10000000))</pre>
        <pre>@(new Random().Next(10, 10000000))</pre>
        <pre>@(new Random().Next(10, 10000000))</pre>
    }
    

    will result in something like (the same result all three times):

    @{
        <pre>116133</pre>
        <pre>116133</pre>
        <pre>116133</pre>
    }
    

    If you can use the same instance of Random, you will continue to get new random values, instead of the same random value. An alternative could also be to use a GUID or something similar - eg:

    @{

    @("u" + Guid.NewGuid().ToString().Replace("-", ""))
    @("u" + Guid.NewGuid().ToString().Replace("-", ""))
    @("u" + Guid.NewGuid().ToString().Replace("-", ""))
    }

    will result in something like:

    @{
        <pre>u89c73303ef234a9987b68e1488104fc5</pre>
        <pre>u86a7cd1df39146af976552077a10dd6b</pre>
        <pre>u1c9b071e0f4e44d0a6cf058be441c2cc</pre>
    }
    
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Dec 21, 2016 @ 16:37
    Jeroen Breuer
    0

    Hi Anders,

    Thanks for the reply. I tried to use Guid.NewGuid().ToString().Replace("-", ""), but that doesn't seem to help.

    That the MVC part has changed is interesting. We have some surface controllers to render parts of LeBlender. I'll investigate if that has changed.

    Here are some screenshots of the live website (Umbraco 7.2):

    enter image description here

    enter image description here

    And here are some screenshots of the local upgraded (Umbraco 7.5) website:

    enter image description here

    enter image description here

    The images are wrong because somehow the ids are still the same (even with GUIDs), but as you can see on the last image some articles are double and at the wrong location. Somehow this happend after the upgrade.

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Dec 22, 2016 @ 13:13
    Jeroen Breuer
    0

    Anders I marked your post as the solution. I replaced (new Random().Next(10, 10000000)) everywhere with Guid.NewGuid().ToString().Replace("-", "") and now everything seems to be working. Some images and blocks are ajax loaded so that's why the screenshots from and live and local could be so different.

    It's still really strange that this code worked on Umbraco 7.2 and not on Umbraco 7.5.

    Jeroen

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Dec 22, 2016 @ 13:26
    Anders Bjerner
    0

    Awesome. I forgot about your reply, but didn't really have anything more to add anyways. So good thing that it now works :D

Please Sign in or register to post replies

Write your reply to:

Draft