所以我在标题中收到错误消息,但我不明白为什么。
此处介绍了如何在视图中引用模型
@model IEnumerable<Lowflix.Models.LendingIndexModel>
此foreach中出现的错误
@foreach (var item in Model)
由于我什至宣布了IEnumerable,因此我无法向自己解释这个错误。它包含多个对象。
这是错误消息:
foreach statemetn cannot operate on variables
of type "Models" because "Models" does not
contain a public instance of GetEnumerator
- 型号:
using Lowflix.Core.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Lowflix.Models
{
public class LendingIndexModel
{
public LendingIndexModel()
{
}
public Guid LendingId { get; set; }
public Guid CustomerId { get; set; }
public Guid CopyId { get; set; }
public String Title { get; set; }
public DateTime StartDate { get; set; }
public DateTime? ReturnDate { get; set; }
public virtual Movie Movie { get; set; }
public virtual Customer Customer { get; set; }
public virtual Copy Copy { get; set; }
}
调试模型: 型号:
+ Model {System.Linq.Enumerable.WhereSelectListIterator
<Lowflix.Core.Entities.Lending,
Lowflix.Models.LendingIndexModel>} System.Collections.Generic.IEnumerable
<Lowflix.Models.LendingIndexModel>
{System.Linq.Enumerable.WhereSelectListIterator
<Lowflix.Core.Entities.Lending,
Lowflix.Models.LendingIndexModel>}
答案 0 :(得分:0)
请尝试以下代码。
@model List<Lowflix.Models.LendingIndexModel>
在“查看”页面中,将IEnumerable更改为List。