There are at least two things wrong here:
First the view is expecting a model of type
demo.mvc.Models.Book
The name implies that this is an individual book, so it would make sense for it to implement
GetEnumerator
which is intended for use with collections such as lists etc. The view is
probably expecting the wrong type (though it could be the case that
Book
is a collection, in which case it should inherit from
IEnumerable
at the very least). You need to check what the type you should be using, I'd expected a View model containing a
List<Book>
or just the list passed directly (though this is less good practise IMO) given what is said in the rest of your code:
csHtml:
@{
ViewBag.Title = "Index";
}
@model List<demo.mvc.Models.Book>
Second your controller gets a list of books, but never passes the data in to the view, assuming you are binging to the list:
public ActionResult Index()
{
List<Book> bk = new List<Book>();
return View(bk);
}
Given that this looks like a sample, I'd suggest you research Model-View-ViewModel (MVVM) in MVC, it'll save a lot of headache as you start to work on more complex things.