I Have following Linq Query in Controller
ViewBag.data=(from cg in db.Colleges
from tn in db.Towns
from ds in db.Districts
where cg.CgTnCode ==tn.TnCode && tn.TnDscode==ds.DsCode
orderby ds.DsCode,tn.TnCode,cg.CgCode
select new
{
cg.CgCode,
cg.CgShName,
cg.CgName,
cg.CgType,
DsCode = ds.DsCode,
DsName=ds.DsName,
TnCode= tn.TnCode,
TnName=tn.TnName,
cg.CgAddr1,
cg.CgAddr2 ,cg.CgAddr3,cg.CgLoca,cg.CgPin,cg.CgPhone,cg.CgFax,cg.CgEmail ,cg.CgWeb,cg.CgOnlyCent});
I want to display all selected fields in View..
I have written code in view to acess ViewBag.data as follows :
@foreach(var entry in ViewBag.data)
{
@entry.CgCode
@entry.CgShName
@entry.CgName
@entry.CgTnCode
@entry.DsCode
}
Its Giving Error as does not contain a definition for 'DsCode'
what should I do can anyone help??