Copied to clipboard

Flag this post as spam?

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


  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Feb 07, 2013 @ 17:36
    Warren Buckley
    0

    Razor Model for XPathCheckboxList

    Hello you wonderful uComponents Dev's.

    Quick question I have a uComponents DataType that is a XPathCheckBoxList DataType that uses a simple XPath to select nodes for this checkbox options for the user, that stores the NodeNames as XML with this simple xPath //WorkType

    I wanted to use the Razor Model Data Binding feature in my Razor so I can fetch the values and iterate over them in a loop like so:

    @{                            
        if (item.HasValue("servicesRendered"))
        {
            var services = item.servicesRendered;
            <span>
                @foreach (var service in services)
                {
                    @service.Name <text> / </text>
                }
            </span>
        }  
    }

     

    I am running Umbraco 4.7.1 with uComponents 4.1.0 and ensured the web.config key ucomponents:RazorModelBinding is set to true.

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

    So if any of you uComponent ninja's can give me some advice or pointers that wouyld be great.

    Thanks,
    Warren :)

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Feb 08, 2013 @ 15:50
    Lee Kelleher
    0

    Hi Warren,

    Did you try the Razor script? If so, what happens?

    The model-binder (in uComponents v4.x) would return the property as a DynamicNodeList object - should be able to loop it as you've already got.

    Cheers, Lee.

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Feb 08, 2013 @ 16:56
    Warren Buckley
    0

    Hey Lee,
    Thanks for getting back to me. This is odd as it is returning a DynamicNodeList object but when I set a break point on the object I get no items in the collection.

    See screengrab

     

    Cheers,
    Warren :) 

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Feb 08, 2013 @ 17:12
    Lee Kelleher
    0

    Hmmm... what values do you have for it in your "umbraco.config"?

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Feb 08, 2013 @ 17:13
    Warren Buckley
    0

    Hey Lee,
    Here is the XML stub stored in the property

    <servicesRendered>
     <XPathCheckBoxList>
     <nodeName>Umbraco development</nodeName>
     <nodeName>Design &amp; HTML</nodeName>
     </XPathCheckBoxList>
    </servicesRendered>

     

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Feb 08, 2013 @ 17:27
    Lee Kelleher
    0

    Ah ha, it's set to use Node Name as the value.  Hmmm... busted - our ModelBinder wont work with it :-(

    If you swap them over to use Node Id, then it will work.

    - Lee

  • 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