Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Jul 26, 2011 @ 17:27
    Ismail Mayat
    0

    multiple values csv with multi node tree picker

    Having a little issue with razor and multi node tree picker. using umbraco 4.7 but latest 4.7.1 umbraco.macroengines the issue is its multi select to be stored as csv when one item selected all good.  When more than one i get issue this is what i am trying todo:

                    <umbraco:Macro  runat="server" language="cshtml">
                          @inherits umbraco.MacroEngines.DynamicNodeContext
                          @foreach (var item in Model.featuredNewsItem.BaseElement.Elements("nodeId"))
                          {
                               var pickedNode = Model.NodeById(item.Value);
    
                               var nId =0;
                               if(pickedNode.newsCategory.Count()>1){
                                    nId = pickedNode.newsCategory[0];
                               }
                               else{
                                    nId = pickedNode.newsCategory;
                               } 
                               var category = Model.NodeById(nId);
    
                                <div class="info fltLeft">
    
                                  <h2><a href="@pickedNode.Url">@pickedNode.Name</a></h2>
                                  <p class="date">@pickedNode.CreateDate.ToString("dd MMMM yyyy")</p>
                                  <p class="trailtext">@pickedNode.teaser</p>
                                  <p class="tag @category.Name.Replace(" ","")"><a href="#">@category.Name</a></p>
                                </div>
                                <div class="pic fltRight">
                                  @if(pickedNode.images.ToString()!=string.Empty){
                                     var i=0;
                                     foreach (var mediaItem in pickedNode.images.BaseElement.Elements("mediaItem")) {
                                            if(i==0){
                                                <a href="@pickedNode.Url"><img src="/[email protected]("Image").Element("umbracoFile").Value&amp;width=278&amp;height=199" alt="@mediaItem.Element("Image").Element("description").Value" /></a>
                                            }
                                            i++;
                                     }
                                  }
                                </div>
                          }
    
                    </umbraco:Macro>

    it fails with error Error loading Razor Script 'decimal' does not contain a definition for 'Count' however i thought as per this post http://our.umbraco.org/forum/developers/razor/22474-How-to-get-first-link-from-RelatedLinks-datatype in 471 you can do count.  It seems as though if csv multi select it munges the ids together and there is no way of separating them out.

     

    Any ideas anyone?

     

    Ismail

     

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jul 26, 2011 @ 17:34
    Sebastiaan Janssen
    1

    The problem is that it's doing ducktyping (apparently to decimal as the comma is seen as decimal sign). IMHO, that should be ducktyped to an array of id's (but I'm not sure how that could be tweaked to work better, maybe detect if the comma is after every third number).

    Not sure why you're going to BaseElement though, wouldn't this be enough:

    @foreach(var nodeId in Model.GetProperty("featuredNewsItem").Value.Split(',')) { 
     //do something

     

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jul 26, 2011 @ 17:35
    Sebastiaan Janssen
    0

    Oh I see it's failing elsewhere but you can still apply the same principle, once you Split the value you can do a count (or lenght?) on it.

  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Jul 26, 2011 @ 17:47
    Ismail Mayat
    0

    Sebastiaan,

    just found the post on ducktyping to int so as per you suggestion did GetProperty and it works nicely. 

    Cheers

     

    Ismail

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies