I tried to access the property of model (FilePath) in my Render action, but without success.
I have these models:
public class Offer
{
public int OfferID { get; set; }
public string Reference { get; set; }
public string Title { get; set; }
public virtual ICollection<FilePath> FilePaths { get; set; }
}
public class FilePath
{
public int FilePathId { get; set; }
public string FileName { get; set; }
public virtual Offer Offer { get; set; }
}
In controller offer:
public PartialViewResult Category()
{
var offers = db.Offers
.Include(i => i.FilePaths)
// i tried with .Include(“FilePaths”) with no sucess
.ToList();
return PartialView("_OfferBoxList", offers);
}
Showing with:
@{Html.RenderAction("Category", "Offer");}
The problem is in partial action view:
@foreach (var item in Model)
{
@item.Title // This work
@item.FilePath.FileName // This NOT work
}
Output error:
'System.Data.Entity.DynamicProxies.Offer_278BF6A1F89FB9514329AC922E992AEBD19368D66A4460B6BEBA1BB2256CAFC3' does not contain a definition for 'FilePath'
Thanks for help.
Each
Offerhas a list ofFilePathinstances (ICollection<FilePath> FilePaths), so you can't just access theOffer.FilePath.FileNameproperty, you have to get for instance the first one (depending on what you need), using something like: