Copied to clipboard

Flag this post as spam?

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


  • Michael Beever 74 posts 155 karma points
    Jun 02, 2020 @ 13:13
    Michael Beever
    0

    Razor Where()

    Hello,

    I am trying to only pull certain items into a list trying this

    var newsposts = selection.OrderByDescending(x => x.CreateDate).Where(x => x.GetPropertyValue<string>("newType2") == @PageTheme).ToList();
    

    Page loads but nothing is brought back. I have 1 news page that I want all content to display on but if you are in a certain page theme only to bring back the news for that page. I am using an IF statement below to do this but the pagnation doesn't work.

    Any ideas?

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Jun 02, 2020 @ 14:12
    Kevin Jump
    0

    Hi Michael,

    there might be other things inside the view but from that bit of code, i think you can remove the @ symbol from @PageTheme

    so it looks like:

    var newsposts = selection.OrderByDescending(x => x.CreateDate).Where(x => x.GetPropertyValue<string>("newType2") == PageTheme).ToList();
    

    as you are already inside a code block in razor you don't need the @ symbol to identify the variable.

  • Michael Beever 74 posts 155 karma points
    Jun 02, 2020 @ 14:16
    Michael Beever
    0

    Hi I will try this but I think it is not possible as i am using a multi selection list when creating the news article to allow the items to appear on multiple pages.

  • Yakov Lebski 591 posts 2346 karma points
    Jun 02, 2020 @ 20:13
    Yakov Lebski
    0

    Also I think is better change order of statements, first where and after order, of course PageTheme should be string

    var newsposts = selection.Where(x => x.GetPropertyValue<string>("newType2") == PageTheme).OrderByDescending(x => x.CreateDate).ToList();
    
Please Sign in or register to post replies

Write your reply to:

Draft