Copied to clipboard

Flag this post as spam?

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


  • CamT 5 posts 85 karma points
    May 18, 2021 @ 14:03
    CamT
    0

    Dynamic Sort Order

    Hi

    I have a bit of code returning some results which works fine however the editor need the option to change the results order depending on the page they are being listed.

    Assumed it would be pretty simple but have been going round in circlues for a while now.

    This code works:

      if (Model.Results.BlogPostList.Any())
            {
         var sortedList = Model.Results.BlogPostList.OrderByDescending(x => x.Value<DateTime>("postDate"));
    
         @foreach(var item in sortedList)
    
        {
        <p>results</p>
    
        }
    }
    

    But would like to add something like to the code:

      if (sortOrder == "Acending")
         {
            var sortedList = Model.SearchResults.BlogPostList.OrderBy(x => x.Value<DateTime>("postDate"));
         }     
    

    However when I do add an if statment in here end up with the error: CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'string' and 'method group'

    Any Ideas what I'm missing?

    Thanks

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    May 18, 2021 @ 14:20
    Søren Gregersen
    0

    Could you post a bit more of the error you get.

    It seems you are comparing a string against a method, but a bit had to see in your posted code where it is.

  • CamT 5 posts 85 karma points
    May 18, 2021 @ 14:31
    CamT
    0

    Thanks a lot for taking the time to reply.

    When I add a conditional stament to the working code this is the error it's been giving:

    Line 61:        
    Line 62:             
    Line 63:             @foreach(var item in sortedList)
    Line 64:             
    Line 65:             {
    
    error CS0103: The name 'sortedList' does not exist in the current context
    
    error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'string' and 'method group'
    
Please Sign in or register to post replies

Write your reply to:

Draft