Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1287 posts 2744 karma points
    Feb 24, 2014 @ 18:49
    Amir Khan
    0

    OrderBy before Skip throws error

    Hi,

    I have this bit of code looping trough some nodes before pagination. I'm trying to sort the nodes based on a property before rendering the pages, but whenever I put OrderBy before the Skip or Take I get an error "Exception: System.FormatException: Input string was not in a correct format."

    foreach (var item in items.Skip((pages -1)* pageSize).Take(pageSize).OrderBy("dateFiled desc"))

    Anyone know why this would be?

    Thanks!
    Amir

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 24, 2014 @ 19:08
    Fuji Kusaka
    0

    Hi Amir,

    It looks good to me, but can you please post your whole code ?

    I have this working for me 

    var items  = Model.Children.Where("Visible").ToList();
    @foreach(var item in items.Skip((news -1) * psize).Take(psize).OrderBy("dateFiled desc")){
    }
  • Amir Khan 1287 posts 2744 karma points
    Feb 24, 2014 @ 19:48
    Amir Khan
    0

    Hi Fuji, what ended up working for me was moving the OrderBy statement up in the declaration for "items", it seems that it should work both ways though no?


    Here's the code, shortened for brevity.

    @using System;
    @using System.IO;
    @using System.Xml.XPath;
    @using System.Xml;
    @using umbraco.MacroEngines;
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
    //Request Query String
    string filingGroup = Request.QueryString["filingGroup"];

    }


    @{
    var startNodeID = 4083;


    }

    @if (startNodeID != null)
    {
    if (@filingGroup != null) {
    }
    @* Get the start node as a dynamic node *@
    var startNode = Library.NodeById(startNodeID);

    //Pagination
    var pageSize = 20;
    var pages = 1; int.TryParse(Request.QueryString["page"], out pages);
    var items = startNode.Children.Where("Visible").OrderBy("dateFiled desc");
    var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);

    if (pages > totalPages)
    {
    pages = totalPages;
    }
    else if (pages < 1)
    {
    pages = 1;
    }
    // Pagination nav
    if(totalPages >1)
    {
    <div class="pagination">
    @if (pages > 1)
    {
    <span class="prev"><a href="?page=@(pages-1)">Prev</a></span>
    }

    @if (pages < items.Count())
    {
    <span class="next"><a href="?page=@(pages+1)">Next</a></span>
    }
    </div>

    }
    if (startNode.Children.Where("Visible").Any())
    {

    else {
    foreach (var item in items.Skip((pages -1)* pageSize).Take(pageSize))
    {

    string filingDate = @item.dateFiled;
    int year = int.Parse(filingDate.Substring(0, 4));
    int month = int.Parse(filingDate.Substring(4, 2));
    int day = int.Parse(filingDate.Substring(6, 2));

    <li class="filingRow filing clearfix">
    <div class="date">
    @month.@day.@year
    </div>
    <div class="form">
    <a href="/investor-relations/document-dashboard/sec-filings/filing/[email protected]">@item.formType&#8212;@item.formDescription</a>
    </div>
    <div class="filingGroup">
    @item.formGroup
    </div>
    <div class="downloadLinks clearfix">
    <div class="iconWrapper clearfix">
    <div class="icon">
    @if (@item.dOCLink != String.Empty) {
    <a href="@item.dOCLink"><img src="/images/icons/docLink_on.png" /></a>
    } else {
    <img src="/images/icons/docLink_off.png" />
    }
    </div>
    <div class="icon">
    @if (@item.xLSLINK != String.Empty) {
    <a href="@item.xLSLINK"><img src="/images/icons/xlsLink_on.png" /></a>
    } else {
    <img src="/images/icons/docLink_off.png" />
    }
    </div>
    <div class="icon">
    @if (@item.pDFLINK != String.Empty) {
    <a href="@item.pDFLINK"><img src="/images/icons/pdfLink_on.png" /></a>
    } else {
    <img src="/images/icons/docLink_off.png" />
    }
    </div>
    <div class="icon last">
    @if (@item.xBRLLink != String.Empty) {
    <a href="@item.xBRLLink" target="_blank"><img src="/images/icons/xbrlLink_on.png" /></a>
    } else {
    <img src="/images/icons/xbrlLink_off.png" />
    }
    </div>
    </div>
    </div>
    </li>

    }
    }
    </ul>
    }

    // Pagination nav
    if(@filingGroup != null){
    if(totalPages >1)
    {
    <div class="pagination">
    @if (pages > 1)
    {
    <span class="prev"><a href="?filingGroup=@filingGroup&page=@(pages-1)">Prev</a></span>
    }

    @if (pages < items.Count())
    {
    <span class="next"><a href="?filingGroup=@filingGroup&page=@(pages+1)">Next</a></span>
    }
    </div>

    }
    } else {
    if(totalPages >1)
    {
    <div class="pagination">
    @if (pages > 1)
    {
    <span class="prev"><a href="?page=@(pages-1)">Prev</a></span>
    }

    @if (pages < items.Count())
    {
    <span class="next"><a href="?page=@(pages+1)">Next</a></span>
    }
    </div>

    }
    }
    }
  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 25, 2014 @ 05:40
    Fuji Kusaka
    0

    Great to know you got it working

Please Sign in or register to post replies

Write your reply to:

Draft