Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Oct 18, 2012 @ 13:18
    Anthony Candaele
    0

    Razor script broken after upgrade to uComponents 5.0

    Hi,

    I upgrade uComponents from version 4 to version 5.0 on my Umbraco 4.9.0 website.

    The script where I access an MNTP property and try to read it's values is broken though:

    ...

    @if (Model.HasValue("memberPublications"))
        { 
            <br />
            <h3>Recent Publications</h3>
            foreach (var id in Model.memberPublications)
            {
                dynamic publication = new DynamicNode(id.InnerText);
               <p>- <a href="@publication.NiceUrl" title="@publication.publicationTitle">@publication.publicationTitle</a></p>
            }
         }

    ...

    If I debug in VS I get this error message:

    The call is ambiguous between the following methods or properties: 'umbraco.MacroEngines.DynamicNode.DynamicNode(int)' and 'umbraco.MacroEngines.DynamicNode.DynamicNode(string)'

    on the line:

    dynamic publication = new DynamicNode(id.InnerText);

    Does anyone has an idea what's going on?

    Thanks for your help,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 18, 2012 @ 14:56
    Anthony Candaele
    0

    ok, found the issue by replacing the property InnerText with Id

    so the line of code:

    dynamic publication = new DynamicNode(memberpublication.Id);

    (I changed the name of my looping object from "id" to "memberpublication")

    my script is working now.

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 18, 2012 @ 15:24
    Anthony Candaele
    0

    stumpled upon another issue after upgrade to uComponents 5.0

    this code doesn't work anymore:

    *the property publicationAuthors is of type uComponents MultiTextString

    @foreach (var author in @Model.publicationAuthors)

                        {                        

                            if (!author.IsNotFirst())

                            {

                                if (author.IsNotLast())

                                {

                                    @Html.Raw("; ")      

                                    @author.Id      

                                }

                                else

                                {

                                    @Html.Raw(" & ")

                                    @author.Id

                                }

                            }

                            else

                            {

                                @Html.Raw(" ")

                                @author.Id

                            }

                        }

    The problem seems to lay in the 'author' looping object which is now of type String. And therefore the IsNotFirst() and IsNotLast() methods aren't recognized on this String object.

    Before the upgrade to uComponents 5.0 this code worked perfectly

    Anyone got an idea?

    Thanks for your help,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 18, 2012 @ 16:30
    Anthony Candaele
    0

    ok, I solved the abovementioned issue by adding a counter to my code and subtracting 1 after each iteration like this:

    int count = 0;

    @if (Model.HasValue("publicationAuthors") && Model.publicationAuthors.Count > 0)

                        {

                            count = 0;

                            count = Model.publicationAuthors.Count;

                             foreach (var author in @Model.publicationAuthors)

                                {                       

                                  if (count - 1 != 0)

                                  {

                                      @author<text>, </text>

                                      count--;      

                                  }

                                  else

                                  {

                                      @author

                                  }                

                                }

                        }

    And although this code is more elegant than the abovementioned code, it still worries me why the previous code stopped working after the upgrade to uComponents is broken, as I didn't read anything about breaking changes in uComponents 5.0

    Hope some will shed some light on this.

    Thanks,

    Anthony

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Oct 19, 2012 @ 11:23
    Lee Kelleher
    0

    Hi Anthony,

    I held off replying yesterday as I was going to suggest that it was a Razor model-binding issue, but there were no code differences with that between uComponents v4.x and v5 ... now your follow-up posts do sound like that's the cause.

    There is an option to disable the model-binding for Razor, by using this appSettings key:

    <add key="ucomponents:RazorModelBinding" value="false" />

    ... but since you've already changed your Razor scripts to use the model-binding, I wouldn't bother reverting back. :-)

    Thanks, Lee.

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 19, 2012 @ 14:36
    Anthony Candaele
    0

    Hi Lee,

    Thanks for your feedback. I won't revert back now, because as I mentioned I find the solution with the counter a bit more elegant. In some cases the IsLast(), IsFirst(), ... methods may come in handy though.

    I'm glad I sorted this out, as it may help other people having broken scripts after upgrading from uComponents 4+ to uComponents 5.0

    greetings,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft