使用 orderby 对动态模型进行排序
Sort dynamic model with orderby
我正在将转移到动态模型的 2 table 合并为 cshtml 部分中的 1 table。
我想按列 (OrderBy) 对 table 进行排序。我怎样才能做到这一点?如果你能帮忙,我会很高兴。
(Whosebug 促使我写更多的文字,但我不知道关于这个话题还有什么要说的。我该如何解决?)
[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>
我没有使用 dynamic 解决这个问题,而是使用 linq。
我正在将转移到动态模型的 2 table 合并为 cshtml 部分中的 1 table。
我想按列 (OrderBy) 对 table 进行排序。我怎样才能做到这一点?如果你能帮忙,我会很高兴。 (Whosebug 促使我写更多的文字,但我不知道关于这个话题还有什么要说的。我该如何解决?)
[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>
我没有使用 dynamic 解决这个问题,而是使用 linq。