控制器
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(); }
}
查看
@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>
}
我认为我在视图中歪曲变量类型,解决方案是什么?谢谢你,
答案 0 :(得分:0)
Model
必须是已知或可理解的类型。将其更改为
@model IEnumerable<FirmaCek>
或@model IEnumerable<YourModelTypeInYourController>
。 model
由Index
操作发送,并且视图中的类型应该相同。
答案 1 :(得分:0)
您将模型声明为IEnumerable,但尝试将其与匿名类型列表一起使用。
您的选择是:
以下是非匿名创作的示例:
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();