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:
public class EstimateDetailsModel : IEnumerable<string>
{
public string Dma { get; set; }
public string Callsign { get; set; }
public string Description { get; set; }
public IEnumerator<string> GetEnumerator()
{
yield return Dma;
yield return Callsign;
yield return Description;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
(I have capitalised the properties, which is the normal style.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With