-1
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;

This is codebehind in my ".cs" page.

var Urun = ViewBag.urun;
<h3 class="Baslik"><%:Urun.UrunAdi %></h3>

This is my code ".aspx" page.

But i get 'object' does not contain a definition for 'UrunAdi' error?


I solved my problem via another method:

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);

And my aspx page code:

<%
var Urun = Json.Decode(ViewBag.urun);
%>
<h3 class="Baslik"><%:Urun.UrunAdi %></h3>

This method work very good :) Thanks everyone..

CaKaL
  • 402
  • 1
  • 6
  • 16
  • 1
    Why you are assigning it **UrunAdi= u.UrunAdi,** Value. Can't you use only **u.UrunAdi,**? – RL89 Sep 17 '12 at 09:03
  • ok i changed -select new{u.UrunID,u.UrunAdi}- but don't work :( – CaKaL Sep 17 '12 at 10:25
  • Possible duplicate of ['object' does not contain a definition for 'X'](https://stackoverflow.com/questions/7652749/object-does-not-contain-a-definition-for-x) – dylan-myers Sep 25 '17 at 11:38

1 Answers1

2

You are using an anonymous object here:

Please have a look to this Link

'object' does not contain a definition for 'X'

Community
  • 1
  • 1
RL89
  • 1,866
  • 5
  • 22
  • 39