Using sorting(oredrBy) in the template with module Projection Layouts

Topics: General, Troubleshooting, Writing modules, Writing themes
Feb 8, 2013 at 10:26 AM
Hi, all!
I'm trying to get list of most popular articles. I use Shape type of Projections (Projection Layouts) and sorting model.ContentItems directly in cshtml template.
Projections Filters: all Contet Types == Article
Projections Sorting: none
Projections Layouts: Shape (Shape name - MostPopularList_SidebarRight)

Here is my MostPopularList.SidebarRight.cshtml:
@using Orchard.ContentManagement;
@{
    var contentManager = WorkContext.Resolve<IContentManager>();
    var items = contentManager.Query("Article").List();
    var sorted = items.OrderByDescending(c => c.As<UserViewPart>().TotalViews);
    //IEnumerable<ContentItem> blogPosts = Model.ContentItems;
    //var ter = blogPosts.ToList();
    //var sorted = ter.OrderByDescending(c => c.As<UserViewPart>().TotalViews);
    int iterator = 0;
}

<div class="title-theme-wrapper">
    <p> Popular Articles</p>
</div>

<ul class="content-items">
    @foreach (dynamic item in sorted)
    {
        if (iterator == 0)
        {
        <li class="fpmp-sidebar">
            <h3><a title="Go to: @item.TitlePart.Title" href="@item.AutoroutePart.Path">@item.TitlePart.Title</a></h3>
            <a title="Go to: @item.TitlePart.Title" href="@item.AutoroutePart.Path">
                <img src="@Href(item.MainImagePart.PublicationImage.Url)" title="Go to: @item.SubTitle.SubTitle.Value" alt="@item.MainImagePart.PublicationImage.AlternateText"/>
            </a>
            <a class="slofp" title="Go to: @item.TitlePart.Title" href="@item.AutoroutePart.Path">@item.SubTitle.SubTitle.Value (@item.UserViewPart.TotalViews) <span class="scobs">&#187;</span></a>
            <hr/>
        </li>
        }
        else
        {
        <li>
            <a title="Go to: @item.TitlePart.Title" href="@item.AutoroutePart.Path">@item.TitlePart.Title (@item.UserViewPart.TotalViews)</a>
            <hr/>
        </li>
        }

        iterator++;
    }
</ul>
I'm sorting by UserViewPart from the Content View Counter module.

In Homepage code working just fine, but on the other pages happenings something strange...
All TotalViews in my list showing 0 and sorting not working
Other strange thing: artile url path - instead of /space/article-title i get /space/space/article-title

Where is my mistake?

P.S. Sorry for bad english... :(