Controller
public ActionResult Index()
{
try
{
using (var DB = new CekTakipOtomasyonEntities())
{
var model = (from f in DB.FirmaCek
join k in DB.KullaniciHesap
on f.KullaniciID equals k.ID
select new
{
f.ID,
f.Tutar,
f.KayitTarihi,
f.VadeTarihi,
tutar = f.Tutar,
f.SeriNo,
f.Banka,
f.Sube,
f.Iban,
f.Kesideci,
f.CiroEdilen,
f.TeslimEden,
k.Ad,
k.Soyad
}).OrderByDescending(f => f.KayitTarihi).ToList();
if (model == null) return View();
return View(model);
}
}
catch { return View(); }
}
View
@using CekTakipOtomasyon.Models
@model IEnumerable<FirmaCek>
@foreach (var firma in Model)
{
<tr>
<td><input type="checkbox" name="secili" value="@firma.ID" /></td>
<td>@firma.KayitTarihi.ToLongDateString()</td>
<td>@firma.VadeTarihi.Value.ToLongDateString()</td>
<td>@Convert.ToInt32(firma.Tutar).ToString() TL</td>
<td>@firma.SeriNo</td>
<td>@firma.Banka</td>
<td>@firma.Sube</td>
<td>@firma.Iban</td>
<td>@firma.Kesideci</td>
<td>@firma.CiroEdilen</td>
<td>@firma.TeslimEden</td>
<td>@firma.KullaniciHesap.Ad @firma.KullaniciHesap.Soyad</td>
<td><button id="btn_Guncelle" value="@firma.ID" class="btn btn-block btn-info">Güncelle</button></td>
</tr>
}
I think I am misrepresenting variable type in view, what is the solution? Thank you from now
Model
must be known or understandable type in your view. Change it as
@model IEnumerable<FirmaCek>
or @model IEnumerable<YourModelTypeInYourController>
. model
is sent by Index
action and it should have same type in the view.
You're declaring your model as IEnumerable but try to use it with a List of anonymous types.
Your options are:
Here's an example of non-anonymous creation:
var model = (from f in DB.FirmaCek
join k in DB.KullaniciHesap
on f.KullaniciID equals k.ID
select new MyViewModel
{
ID = f.ID //add properties here
}).OrderByDescending(f => f.KayitTarihi).ToList();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.