Sort values from one li by date C #

0

Is it possible to sort the values of a dropdown per day? Is there a order by or do you really have to do if's for that?

Code sample:

 <span class="dropdown">
    <button class="btn btn-search dropdown-toggle" type="button" id="horas" data-toggle="dropdown">
        <span id="newdisp">Nova disponibilidade</span><span class="caret" style="border-top:4px solid #FFF;"></span>
    </button>
    <ul class="dropdown-menu" role="menu" aria-labelledby="horas" onclick="newhour(event);">
        @{
            foreach (ScriptorContent horas in Model.Parts.Channel[0].Contents)
            {

                int empresa = (horas.Parts.titulo).LastIndexOf("- ");
                if (empresa > 0)
                {
                    string nome = (horas.Parts.titulo).Substring(empresa + 2);

                    if (nome == a.Parts.empresa[0].Parts.Name)
                    {
                        string horainicio = (horas.Parts.inicio).ToString("H:mm");
                        string horafim = (horas.Parts.fim).ToString("H:mm");
                        string data = (horas.Parts.inicio).ToString("dd/MM/yyyy");
                        <li role="presentation"><a role="menuitem" tabindex="-1">@data @horainicio - @horafim</a></li>
                    }
                }
            }
        }
    </ul>
</span>
    
asked by anonymous 18.12.2014 / 12:24

1 answer

1

One solution to your problem would be to use OrderBy in your foreach , thus:

foreach (ScriptorContent horas in Model.Parts.Channel[0].Contents.OrderBy(a=>a.Campo))
    
18.12.2014 / 13:25