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

I use two DataContext objects to return separate AsQueriable () data arrays and then connecting them using linq. The data construct works fine, when I pass this combined data set to the view, I get the error "object" does not contain a definition for "Name".

During the debugging session, I clearly see that both the parent model and each element in the foreach loop have all the data and keys visible / available. I am very confused.

Many of the other q & a's on stackoverflow.com that match this problem do not solve my problem and, as a result, will appreciate a fresh set of eyes and hopefully a solution to this problem.

Many thanks! - code time:

Data construction

        public ActionResult SplashImages()
        {
            var g = (from i in GetGallerySplash() join o in GetFestivals() on i.Festival equals o.ID orderby i.Rating descending select new {i.Photo, i.OwnedBy, i.Rating, o.Name });
            Response.ContentType = "text/xml";
            return View(g);
        }

        private IEnumerable<Gallery> GetGallerySplash()
        {
            GallerysDataContext gdc = new GallerysDataContext();
            return (from i in gdc.Galleries orderby i.Rating descending select i).Take(15).AsQueryable();
        }

        private IEnumerable<Festival> GetFestivals()
        {
            FestivalsDataContext fdc = new FestivalsDataContext();
            return (from i in fdc.Festivals select i).AsQueryable();
        }

VSExpress Error Screen: Exception screenshot

. !

+5
3

IEnumerable, .

public class GalleryModel
{
    public IEnumerable<Gallery> Galleries { get; set }
    public IEnumerable<Festivals> Festivals { get; set; }
}

...Inherits="System.Web.Mvc.ViewPage<GalleryModel>"

, .

<% foreach (var t in Model.Galleries) ...
+4
+1

Try changing the for loop to:

<% foreach (dynamic t in Model) { %>

Use varcauses the type to be tinferred as object.

-1
source

All Articles