Copied to clipboard

Flag this post as spam?

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


  • umbracocool 108 posts 197 karma points
    May 25, 2013 @ 09:45
    umbracocool
    0

    How to pass variables to OrderBy in Razor?

    Hello friends!, I am doing a sort by a select field. When you choose one of the options, since this value is Obtained. Then this value, I would pass it on to OrderBy(), dynamically. Look at my code:

    var vars = "date-desc";
    var order = vars.Split("-");
    var nodes = Model.NodeById(@Model.Id).Descendants("Clothes").Where("Visible").OrderBy("createDate "+ order[1]);

    If you have any better idea to to do this, please let me know. Thank you!

  • umbracocool 108 posts 197 karma points
    May 29, 2013 @ 07:19
    umbracocool
    100

    I found the solution:

    var vars ="date-desc";
    var order = vars.Split("-");
    var searchBy = "createDate" + order[1];
    var nodes =Model.NodeById(@Model.Id).Descendants("Clothes").Where("Visible").OrderBy(searchBy);
  • 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