I created the following view model for an MVC application. What I’d like to do is make it an IEnumerable class so that I can iterate through the data in my page using a foreach statement.
public class EstimateDetailsModel
{
public string dma { get; set; }
public string callsign { get; set; }
public string description { get; set; }
}
In case it’s relevant, here is the corresponding Linq query in my repository that instantiates the EstimatesDetailsModel class:
public IEnumerable<EstimateDetailsModel> GetEstimateDetails(int id)
{
var estimateDetails = from e in db.Estimates
join es in db.EstimateStations on e.EstimateID equals es.EstimateID
join s in db.Stations on es.StationID equals s.StationID
join m in db.Markets on s.MarketID equals m.MarketID
where e.EstimateID == 1
select new EstimateDetailsModel { dma = m.DmaName, callsign = s.CallSign, description = s.StationDescription };
return estimateDetails;
}
Perhaps you are looking for something like this:
(I have capitalised the properties, which is the normal style.)