Copied to clipboard

Flag this post as spam?

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


  • Jason Mackay 98 posts 149 karma points
    Feb 15, 2013 @ 10:26
    Jason Mackay
    0

    Ultimate Picker in Razor

    Hi guys,

    I have finally made the move from using usercontrols to making Razor controls instead but I have a problem that I cant seem to fix.

    I am using the Ultimate Picker, that from a checkbox picks up a child node defined under a seperate section(from Parent Node). On a page a user can select which of these picks they want on the page. 
    My question is how do you get the NodeId's then use them in a foreach loop. I know how to do this in C# using the getProperty and seperating the array by comma delimating, I'm just not sure how its done in Razor.

    This is my razor so far, this basically just outputs all the nodes under a certain node: there is some other logic, which I guess is pretty simple but my Razor knowledge isn't quite there.

    @{

    var whiskydepos = @Model.NodeById(1079);
        foreach (var whisky in whiskydepos.Children)
        {
            int mediaId = 0;
            mediaId = string.IsNullOrEmpty(@whisky.whiskyImage.ToString()) ? mediaId : int.Parse(@whisky.whiskyImage.ToString());
            dynamic Picture = Model.MediaById(mediaId);
    <div class="whiskyItem">
    <p>@whisky.whiskyName</p>
    <img src="@Picture.UmbracoFile" class="whiskyItemImg"  />
    </div>
        }
    }

    Thanks for any help in advance.

    Jason

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 15, 2013 @ 10:33
    Fuji Kusaka
    0

    Hi Jason,

    Not sure what what you are asking here ! Are you looking for the parent nodeId ?

    dynamic Picture = Model.MediaById(mediaId);
    <div>
    <p>@whisky.Parent.Name</p>
    </div>
  • Jason Mackay 98 posts 149 karma points
    Feb 15, 2013 @ 10:46
    Jason Mackay
    0

    No sorry - my question was written hastily, looking for a way to get the nodes given in the Ultimate Picker data type, so if 3 out of the 5 nodes it would pass back 3 nodeId's.

    I know in C# I could do something like:
    Node currentNode = Node.GetCurrent();
    string [] testItems = currentNode.GetProperty("myDataTypeName").Value.Split(",");

    And that would give me an array of the 3 NodeId's - I am not sure how this would translate in to Razor, or if there would be a better way of doing this in Razor.

    Thanks 

  • Jason Mackay 98 posts 149 karma points
    Feb 15, 2013 @ 14:13
    Jason Mackay
    0

    Right think I've got it, I think it is very similar to C# and it should look like this:

    var currentNode = umbraco.NodeFactory.Node.GetCurrent();
    var panelStory = @currentNode.GetProperty("panelTest").Value;
    string[] tests = panelStory.Split(','); 

    If anyone knows of an easier way then let me know.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 15, 2013 @ 17:49
    Jeroen Breuer
    0

    If you're using Razor (in macro's and not MVC) you could probably also do something like this:

    string[] tests = Model.panelTest.Split(','); 

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft