I've been trying to get a better grasp on Model and ViewModel design. And for most of you out there, this is probably a silly question. For starters, here is my model:
public class Cities
{
[Key]
public int CityID { get; set; }
public string City { get; set; }
public int Miles { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
}
Now, when I create my ViewModel within my presentation layer, can I just use IEumerable<> to pass all records within my Cities table:
public class CitiesViewModel
{
public IEnumerable<Cities> Cities { get; set; }
}
And then I could loop through all records with my Controller:
[HttpGet]
public ActionResult List()
{
CitiesViewModel model = new CitiesViewModel
{
Cities = repository.Cities
.OrderBy(p => p.City)
};
return View(model);
}
Or, should I just pass in the only data I want my View to have access to:
public class CitiesViewModel
{
//public IEnumerable<Cities> Cities { get; set; }
public string City { get; set; }
public string State { get; set; }
}