var Urun = (from u in db.urunlers.Where(x => x.Yayinlama == "1")
where u.UrunID == id
select new
{
u.UrunID,
UrunAdi= u.UrunAdi,
u.UrunAciklama,
u.YorumIzni
}).SingleOrDefault();
ViewBag.urun = Urun;
这是我的“.cs”页面中的代码隐藏。
var Urun = ViewBag.urun;
<h3 class="Baslik"><%:Urun.UrunAdi %></h3>
这是我的代码“.aspx”页面。
但我得到“对象”不包含“UrunAdi”错误的定义?
我通过另一种方法解决了我的问题:
JavaScriptSerializer js = new JavaScriptSerializer();
var Urun = (from u in db.urunlers.Where(x => x.Yayinlama == "1")
where u.UrunID == id
select new {
u.UrunAdi,
u.UrunID,
u.AltKategoriID,
Uretici=db.ureticilers.Where(x=>x.UreticiID==u.Uretici).Select(x=>x.UreticiAdi).FirstOrDefault()
}).SingleOrDefault();
ViewBag.urun = js.Serialize(Urun);
还有我的aspx页面代码:
<%
var Urun = Json.Decode(ViewBag.urun);
%>
<h3 class="Baslik"><%:Urun.UrunAdi %></h3>
这种方法效果很好:) 谢谢大家..