'Sort dynamic model with orderby
I am combining 2 tables that I transferred to the dynamic model into 1 table in the cshtml part.
And I want to sort that table by a column(OrderBy). How can I do that? I will be glad if you help. (Stackoverflow is pushing me to write more text, but I don't know what more to say about this topic. How can I fix?)
[HttpPost]
public ActionResult GAdiSoyadiSirala()
{
var person = db.Personeller.ToList();
var girisCikis = db.GirisCikisTarihleri.ToList();
//person = person.OrderBy(x => x.AdiSoyadi).ToList();
dynamic mymodel = new ExpandoObject();
mymodel.Personel = person;
mymodel.GirisCikis = girisCikis;
return View("GirisCikislar", mymodel);
}
//The part where I call the GirisCikislar view
public ActionResult GirisCikislar()
{
var person = db.Personeller.ToList();
var girisCikis = db.GirisCikisTarihleri.ToList();
dynamic mymodel = new ExpandoObject();
mymodel.Personel = person;
mymodel.GirisCikis = girisCikis;
return View(mymodel);
}
GirisCikislar.cshtml:
@using PersonelTakipMVC.Models;
@model dynamic
<table class="table table-bordered">
<tr>
<th>PersonelID</th>
@*<th>Adı Soyadı</th>*@
<th>
//When I click this button, the GAdiSoyadiSirala method works.
@using (Html.BeginForm("GAdiSoyadiSirala", "Home", FormMethod.Post))
{
<button class="btn">Adı Soyadı🔻</button>
}
</th>
<th>Tarih</th>
<th>Giriş/Çıkış</th>
</tr>
<tbody>
@foreach (var gc in @Model.GirisCikis)
{
<tr>
<td>@gc.PersonelID</td>
@foreach(var p in @Model.Personel) {
if(gc.PersonelID == p.PersonelID) {
<td>@p.AdiSoyadi</td>
break;
}
}
<td>@gc.Tarih</td>
@if (gc.GirisCikis == 0)
{
<td>Giriş</td>
}
else
{
<td>Çıkış</td>
}
</tr>
}
</tbody>
Solution 1:[1]
Instead of solving this problem using dynamic I did it using linq.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | erenjeager |