Copied to clipboard

Flag this post as spam?

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


  • Aaron 6 posts 26 karma points
    Apr 29, 2013 @ 21:33
    Aaron
    0

    Display posts that have multiple categories selected?

    Hello,

     

    I have a doctype that has a category checkboxlist data type on it. For my navigation I am trying to filter it based off what is selected for the category checkboxlist. The following code works fine for when I am trying to pull the pages with just one category selected.

     @foreach (var items in pages) {
    
                                if (items.category.Contains("Future")) {
    
                                    <li><a href="@items.Url">@items.Title</a></li>
                                }
                            }
    I was hoping the contains would work and pull the pages that also have other checkboxlists checked as well. Unfortunately this causes the script to not pull anything. Is there something special I should be doing when dealing with multiple checked checkboxes? When I try to return the value of the checkbox property when two are selected I get nothing. Unlike when just one thing is checked. Am I going about this the wrong way? Thanks for any help!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 01, 2013 @ 11:17
    Jeavon Leopold
    0

    Hi, I don't see anything wrong with what you have done, could it be a case sensitivity issue? Maybe try:

           if (items.category.IndexOf("future", StringComparison.OrdinalIgnoreCase) >= 0)
          {
              <li><a href="@items.Url">@items.Title</a></li>
          }

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 01, 2013 @ 20:40
    Jeavon Leopold
    0

    Also, what version of Umbraco are you using?

  • Aaron 6 posts 26 karma points
    May 01, 2013 @ 21:14
    Aaron
    0

    I am using Umbraco v6.0.2.

    This is above that code, maybe there is a problem here?

        var navRoot = Model.AncestorOrSelf();
        var pages = navRoot.DescendantsOrSelf("Page");


  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 01, 2013 @ 21:35
    Jeavon Leopold
    1

    Interesting, i think i actually saw that behaviour in V6.0.2 but didn't beleive it, I then tried on a clean v6.0.3 and it worked fine. Could you try upgrading? I think you will need to upgrade to to v6.0.5 for the security patch very soon anyway :-)

  • Aaron 6 posts 26 karma points
    May 01, 2013 @ 22:06
    Aaron
    0

    Wow you were right! It does look like 6.0.2 has an error with multiple checkbox values. I upgraded to 6.0.5 and my original method works fine. I really appreciate the help!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 01, 2013 @ 22:22
    Jeavon Leopold
    0

    Awesome! Glad to have helped. Could you please mark the upgrade comment above as solution in case anyone else the same issue. Thanks!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 02, 2013 @ 12:03
    Jeavon Leopold
    0

    FYI, the issue and resolution is detailed here http://issues.umbraco.org/issue/U4-1882

Please Sign in or register to post replies

Write your reply to:

Draft