Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 22, 2013 @ 18:36
    Fuji Kusaka
    0

    Converting Content Picker Id to NiceUrl

    Hi guys, 

    I just cant get this working and am pretty sure its something very simple. 

    I have a content Picker in my media section and when i try to convert the content id to int32 so as to get the url my razor file just crash. 

    Anyone mind having a look at this ?

     var x = docFolder.getProperty("mcr").Value;
     int id = Convert.ToInt32(x);
    dynamic n = new DynamicNode(id);
    @n.Url

    did try this as well

    dynamic l = Library.NodeById(x);

     

    //fuji

     

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 22, 2013 @ 20:30
    Ali Sheikh Taheri
    0

    Hi Fuji,

    Could you please post the error here so I can see what's going wrong?

    Thanks

    Ali

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 22, 2013 @ 20:33
    Fuji Kusaka
    0

    The file is saved without error but as soon as you render it on the front end it just cant load it

    Error loading MacroEngine script 

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 22, 2013 @ 20:40
    Ali Sheikh Taheri
    0

    can you try this?

    var x = docFolder.getProperty("mcr").Value;
    int id; 
    if(Int32.TryParse(x,out id))
    {
        var n = new DynamicNode(id);
        @n.Url
    }
    
  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 22, 2013 @ 20:58
    Fuji Kusaka
    0

    No not working here as well. Getting some ugly error when saving the file

     The best overloaded method match for 'int.TryParse(string, out int)' 

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 22, 2013 @ 22:00
    Fuji Kusaka
    0

    Nothing seems to be working here. Can anyone point out what am doing wrong here

    Here is my whole code

     var DocumentLib = new Media(1143);
        if (DocumentLib.ChildCount > 0)
        {   
           var count = 0;
            IEnumerable<Media> fd = DocumentLib.GetChildMedia().Where(x => x.ContentType.Alias == "Folder");

            

             <ul class="textSlider">
             @foreach (var docFolder in fd)
             {
     
                 if (docFolder.ChildCount > 0)
                 {
     
                     var file = "";

                   

     
                     foreach (dynamic doc in docFolder.GetChildMedia().OrderByDescending(x => x.CreateDateTime).Where(y => y.ContentType.Alias == "File").Take(1))
                     {
                         file = @doc.getProperty("umbracoFile").Value;
         var x = docFolder.getProperty("mcr").Value.ToString();
                         int id = Convert.ToInt32(x);
               var tt = new DynamicNode(id);
                         dynamic n = new DynamicNode(1229); 
                        <li style="color:#000;"> @n.Url @x - @tt.Url - </li>
                     }
                 }
             }
         </ul>
        }
  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 23, 2013 @ 07:07
    Fuji Kusaka
    100

    I finally managed to get this working.

    var contentPicker = docFolder.getProperty("mcr").Value;
                 if (docFolder.HasProperty("mcr") && docFolder.getProperty("mcr").Value != String.Empty)
                 {
                     int id= Convert.ToInt32(contentPicker);
                     dynamic node = new DynamicNode(id);
      }
  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Oct 23, 2013 @ 07:24
    Nathan Woulfe
    0

    I'd move the contentPicker variable inside the if statement too (or get rid of it altogether if you're not using elsewhere), just in the interest of scoping:

        if (docFolder.HasProperty("mcr") && docFolder.getProperty("mcr").Value != String.Empty)
        {
            int id= Convert.ToInt32(docFolder.getProperty("mcr").Value);
            dynamic node = new DynamicNode(id);
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft