Copied to clipboard

Flag this post as spam?

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


  • Ambert van Unen 65 posts 376 karma points
    Apr 03, 2019 @ 19:38
    Ambert van Unen
    0

    Multinodetreepicker and Modelsbuilder

    'Evening

    I'm not used to working with ModelsBuilder, but with Umb8 i'm trying to get stuff to work.. Only running into a minor issue.

    I believe I used to check if a treepicker had any values like this:

    @if(Models.treePickerExample.Any())
    {
       foreach(var item in Models.treePickerExample){
           doStuff();
       }
    }
    

    Or like this @if(Models.treePickerExample.Count() > 0) { foreach(var item in Models.treePickerExample){ doStuff(); } }

    But currently this doens't seem to work, it both passed the check and goes to the foreach, but it breaks when there aren't any items selected.. Am I missing something?

    I've got it working, but it feels like it's not the best method:

    @if (Model.HasValue("treePickerExample"))
        {
            foreach (var item in Model.treePickerExample)
            {
                doStuff();
            }
        }
    

    Or is this the correct way currently? There seems to be a bit of lack of documentation ;-)

  • Ambert van Unen 65 posts 376 karma points
    Apr 11, 2019 @ 07:13
    Ambert van Unen
    100

    Edited it to

    (Model.treePickerExample != null){}
    

    A treepicker returns null if empty, so check if it's not null ;-)

  • 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