Server error in "/" application. Compile Error
Description: An error occurred during compilation of the resource required to provide service to the request. Please check the following specific error details and modify the source code as appropriate.
Compiler Error Message: CS1579: "Web.Models.Book" does not contain a public definition of "GetEnumerator", so a foreach statement cannot work on a variable of type "Web.Models.Book"
SOURCE Error:
|
Line: <td> operations </td> lines: </tr> rows: @foreach (var item in Model) line 19: {line: <tr> |
View Code:
@model list<web.models.book>@{ viewbag.title = "Index";} @Html. ActionLink ("Add", "Add", "book") <br/><br/><table><tr > <td>ID</td> <td> name </td> <td> price </td> <td> Time </ td> <td> Operations </td></tr>@foreach (var item in Model) {<tr> <td> @item. ID </td> <td> @item .name</td> <td> @item .price</td> <td>@ item.time</td> <td> Operations </td></tr>}</table>
Workaround:
The error is the first line, because the default model can not use the Foreach function, so you have to convert, the first line to modify the following code to
@model list<web.models.book>
Or
@model icollection<web.models.book>
As for why please http://www.cnblogs.com/flyfish2012/archive/2013/01/22/2871273.html
The ASP. NET MVC Views page does not contain a public definition of "GetEnumerator"