ASP.NET MVC DATATABLE KULLANARAK VIEW TARAFINDA LİSTELEME
Controller tarafında üzerinde çeşitli işlemler yaptığımız DataTable tablomuzu View tarafına gönderdik ve listeleme yaptık.
Controller tarafı
public ActionResult Rapor()
{
DataTable dtRapor = RaporTablo(Convert.ToDateTime(Session["ILKTARIH"]), Convert.ToDateTime(Session["SONTARIH"]));
return View(dtRapor);
}
View tarafı
@model System.Data.DataTable
<table class="table">
<thead>
<tr>
<th>ŞEHİR</th>
<th>İLÇE</th>
<th>CARİ</th>
<th>AÇIKLAMA</th>
<th>TARİH</th>
<th>TUTAR</th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.Rows.Count; i++)
{
<tr>
<td>@Model.Rows[i]["SehirAdi"]</td>
<td>@Model.Rows[i]["IlceAdi"]</td>
<td>@Model.Rows[i]["CariUnvan"]</td>
<td>@Model.Rows[i]["Ad"]</td>
<td>@Convert.ToDateTime(Model.Rows[i]["HareketTarih"]).ToString("dd.MM.yyyy")</td>
<td>@Convert.ToDouble(Model.Rows[i]["Miktar"]).ToString("N2") @if(@Model.Rows[i]["ParaTip"].ToString()=="1") { @Html.Raw("TRY") } @if(@Model.Rows[i]["ParaTip"].ToString()=="2") { @Html.Raw("USD") } @if(@Model.Rows[i]["ParaTip"].ToString()=="3") { @Html.Raw("EURO") } </td>
</tr>
}
</tbody>
</table>