I am trying to create a View from my Controller, which looks like this.
namespace NorthernDog.Controllers
{
public class GalleryController : Controller
{
// GET: Gallery
public ActionResult Index()
{
DataTable dt = new DataTable();
dt = Data.DataAccess.GetDogs();
Models.Gallery gallery = new Models.Gallery();
foreach (DataRow item in dt.Rows)
gallery.Dogs.Add(new Models.Dog()
{
Id = Convert.ToInt32(item["Id"]),
Name = Convert.ToString(item["Name"]),
Type = Convert.ToString(item["Type"]),
imagePath = Convert.ToString(item["ImagePath"]),
Breeder = Convert.ToString(item["Breeder"]),
State = Convert.ToString(item["State"]),
ZipCode = Convert.ToString(item["ZipCode"]),
BirthDate = Convert.ToDateTime(item["BirthDate"]),
});
return View(gallery.Dogs.AsEnumerable());
}
}
}
My Dog Model looks like this:
namespace NorthernDog.Models
{
public class Dog
{
public int Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string imagePath { get; set; }
public string Breeder { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
public List<string> ImageList { get; set; }
public DateTime BirthDate { get; set; }
}
}
And lastly my Gallery Model looks like this:
namespace NorthernDog.Models
{
public class Gallery : IEnumerable
{
List<Dog> dogs = new List<Dog>();
public List<Dog> Dogs
{
get { return dogs; }
set { dogs = value; }
}
public Gallery()
{
}
public IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}
}
}
So with all that when I try to create the View by right clicking on the Index from the controller and selecting the Gallery as the model I get a
The model item passed into the dictionary is of type 'System.Collections.Generic.List'1[NorthernDog.Models.Dog]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable'1[NorthernDog.Models.Gallery]'
I have tried converting my list to an IEnumerable but haven't been able to get the syntax right. What am I missing?
My question just got marked as a duplicate and maybe it is but I just looked at the other post and it doesn't make any sense to me. So if it is the same problem I don't understand it either and it is not helping me solve my issue.