Copied to clipboard

Flag this post as spam?

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


  • Hugh 30 posts 64 karma points
    Jan 19, 2014 @ 13:21
    Hugh
    0

    Partial View Macro and Umbraco.TypedContent Lambda Issue

    Hi 

    I can not seem to figure out the correct way to do this.  I have a nodes which are new artilces for my site.  Each article can have many categories associated to it (via a multinode tree picker) as well it can be a featured article by a TrueFalse tick box.

    I have the following Partial View Macro that returns the correct articles based on the category id:
    -----------------------------------------------------------------------------

    @inherits Umbraco.Web.Macros.PartialViewMacroPage;
    @using System.Collections;
    @using System.Linq;
    @using System.Xml;
    @using System.Xml.Linq;
    @using umbraco.MacroEngines;
    @using umbraco

    <div id="tab1" class="tab_content">
    <ul>
    @{
    var articleContainerId = 1089;
    var categoryId = 1098;
    var articles = Umbraco.TypedContent(articleContainerId).Descendants("News").Where(x => x.GetPropertyValue<string>("category").Contains(categoryId));

    foreach (var p in articles)
    {
    <li>  
    <span class="aut-tag"> <a href="@p.Url" class="title">@p.GetProperty("pageHeading").Value</a><br/> <span> @p.GetProperty("summary").Value</span> <br/> <a href="@p.WriterName" class="author" title="Post by @p.CreatorName">Posted by @p.CreatorName</a> <span class="entry-date">@p.GetProperty("uBlogsyPostDate").Value</span> </span>
    </li>              

    }
    }
    </ul>
    </div>

    --------------------------------------------------------------------------

    Now this all works fine.  But I want to add to the Lambda statement to check if the Featured Item property is true.  So i tried using something like:
    var articles = Umbraco.TypedContent(articleContainerId).Descendants("News").Where(x => x.GetPropertyValue<string>("category").Contains(categoryId) && x.GetPropertyValue("isFeature") );

    But this does not seem to work.

    Can anyone shed some light on this for me please?

    Thanks

    HR

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 19, 2014 @ 13:32
    Fuji Kusaka
    0

    Hi Hugh,

    have you tried doing ? 

    var articles = Umbraco.TypedContent(articleContainerId).Descendants("News").Where(x => x.GetPropertyValue<string>("category").Contains(categoryId) && x.GetProperty("isFeature").Value =="1"); 


  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jan 19, 2014 @ 14:10
    Jeavon Leopold
    1

    I would suggest this

    var articles = Umbraco.TypedContent(articleContainerId).Descendants("News").Where(x => x.GetPropertyValue<string>("category").Contains(categoryId) && x.GetPropertyValue<bool>("isFeature")); 
    
  • Hugh 30 posts 64 karma points
    Jan 19, 2014 @ 14:57
    Hugh
    0

    Jeavon, that worked perfectly... Thank you!

  • Hugh 30 posts 64 karma points
    Jan 20, 2014 @ 02:50
    Hugh
    0

    Hi all

    I have another issue.  I created a dropdown List datatype for State.  Vales stored are NSW, QLD, NT, WA, ACT, VIC, SA, TAS. 

    My query is:

    vararticles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("state").Contains("VIC"));

    But this is causing an error: Error loading Partial View script (file: ~/Views/MacroPartials/advancedSearchListing.cshtml)  The data stored in the xml output looks like this:       <state><![CDATA[VIC]]></state> 

    I have tried: vararticles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("state").Contains("VIC"));

    and vararticles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("state".ToUpper()).Contains("VIC".ToUpper())); But nothing seems to work. 

    Any ideas please?


  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jan 20, 2014 @ 17:06
    Jeavon Leopold
    0

    Hi Hugh,

    Are you using a Dropdown list multiple or Dropdown list multiple, publish keys or a different property editor (uComponents maybe)?

    Jeavon

  • Hugh 30 posts 64 karma points
    Jan 20, 2014 @ 17:14
    Hugh
    0

     

    just a straight dropdown list as per the screen shot

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jan 20, 2014 @ 17:17
    Jeavon Leopold
    0

    Oooh v7 drop down, I've not tried that, I will look into it

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jan 20, 2014 @ 19:26
    Jeavon Leopold
    0

    Hi Hugh,

    I've just had a good check and I don't seem to have any issue. He is what I tested:

    var articleContainerId = 1068;
    
    var firstOrDefault = Umbraco.TypedContent(articleContainerId);
    if (articleContainerId != null)
    {
        var articles = firstOrDefault.Children.Where(x => x.HasValue("state") && x.GetPropertyValue<string>("state").ToLower().Contains("VIC".ToLower()));
        foreach (var page in articles)
        {
            <p>matched page: @page.Name</p>
        }
    }
    
  • Vance 5 posts 63 karma points
    Jan 21, 2014 @ 00:52
    Vance
    0

    I also tested this code and it's working ok with my project.

    Still, i am working on it.

    i will update you ..thanks !!

Please Sign in or register to post replies

Write your reply to:

Draft