Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello,
Is it possible to orderby Name first and then by price ?
That is : .OrderBy("Name") and if we have two values starting with letter A, then we orderby price.
thanks,
kusum
Hi,
Yes that is possible. To do this use: .OrderBy("Name, Price")
Or .OrderBy("Name, Price desc")
More info: https://umbraco.com/blog/umbraco-razor-feature-walkthrough-part-4/
Hi Kusum,
Yes it's possible to order items however you want if you can write some C# using Linq.
I recommend you download LinqPad it has a bunch of example files to see how it all works.
There is also an Umbraco Driver so you can write Linq against Umbraco database.
Once you have crafted your linq (C#) just add it to your controller action or view (inside Razor).
Example of fluent Linq
Var movies = _db.Movies.OrderBy(c => c.Category).ThenBy(n => n.Name)
You can also use Linq to compose and build up your filters.
var query=(from w in widgets where w.Name.Contains("xyz") select w); var result = flag ? query.OrderBy(w =>w) : query.OrderByDescending(w = w);
Hi Kusum
Better to use Strongly typed objects with Linq methods, there is .ThenBy method available for such cases.
For example:
var items = Model.Siblings().OrderBy(x => x.Name).ThenBy(x => x.GetPropertyValue<double>("price"));
Thanks,
Alex
Thanks David and Alex for replying.
It's working.
Thank you.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Orderby in umbraco 7
Hello,
Is it possible to orderby Name first and then by price ?
That is : .OrderBy("Name") and if we have two values starting with letter A, then we orderby price.
thanks,
kusum
Hi,
Yes that is possible. To do this use: .OrderBy("Name, Price")
Or .OrderBy("Name, Price desc")
More info: https://umbraco.com/blog/umbraco-razor-feature-walkthrough-part-4/
Hi Kusum,
Yes it's possible to order items however you want if you can write some C# using Linq.
I recommend you download LinqPad it has a bunch of example files to see how it all works.
There is also an Umbraco Driver so you can write Linq against Umbraco database.
Once you have crafted your linq (C#) just add it to your controller action or view (inside Razor).
Example of fluent Linq
You can also use Linq to compose and build up your filters.
Hi Kusum
Better to use Strongly typed objects with Linq methods, there is .ThenBy method available for such cases.
For example:
Thanks,
Alex
Hello,
Thanks David and Alex for replying.
It's working.
Thank you.
is working on a reply...