2016-03-22 5 views
0

をというエラーがスローされます。LINQ変数のキャストAsEnumeratorに、まだビューは、私はこの方法でこれを持ってそのSystem.Data.Entity.Infrastructure.DbQuery

 var Student = _db.Students.Join(_db.StudentGrades, s => s.ENumber, 
      sg => sg.StudentENumber, (s, sg) => new { Student = s, StudentGrade = sg }) 
      .Where(sc => sc.StudentGrade.LetterGrade == "A").Select(sgl => new SCourse 
      { 
       LastName = sgl.Student.LastName, 
       CourseCode = sgl.StudentGrade.CourseCode, 
       CourseNumber = sgl.StudentGrade.CourseNumber 
      }); 
     return View(Student.AsEnumerable()); 
    } 

私はビューで期待される結果を表示するために行くとき私はそれが列挙可能ではなく、クエリとしてビューに送られているというエラーを受け取ります。

The model item passed into the dictionary is of 
type 'System.Data.Entity.Infrastructure.DbQuery`1[Practice.ViewModels.SCourse]', 
but this dictionary requires a model item of 
type 'System.Collections.Generic.IEnumerable`1[Practice.ViewModels.AllStudents]'. 

なぜ、列挙可能ではなくクエリ項目を受け取っているとしますか?これはそれとは何かを持っている可能性がある場合はここで

は、ビューの始まりです:

@model IEnumerable<Practice.ViewModels.AllStudents> 

答えて

2

使用

@model IEnumerable<Practice.ViewModels.SCourse> 

代わりの

@model IEnumerable<Practice.ViewModels.AllStudents> 

名前付きモデルを渡します書面。しかし、あなたがモデルを望むビューファイルでAllStudentsなぜこのエラーが発生しているのですか。

+0

私は非常に気が気になりません。ありがとうございました。 – Ryan

+2

これで問題が解決した場合。私は正しいクリックを期待しています。 –

関連する問題