0

我在以下位置有一个 ViewModel:RolesMVC3.Area.Asesor.Models.ListNotesViewModel

如下:

public class ListNotesViewModel
    {
           public decimal IdTime { get; set; }

           public decimal IdArea { get; set; }

           public decimal IdCriterion { get; set; }

           public decimal Notes { get; set; }

           public decimal IdEstudent { get; set; }
    }

我有一个使用这个 ViewModel 的控制器。

如下:

public ActionResult EstudentsQualification()
   {

    var newItems = (from n in db.Qualification
                    join a in db.AREA on n.IdArea equals a.IdArea
                    join e in db.ESTUDENT on n.IdEstudent equals e.IdEstudent
                    join p in db.TIME on n.IdTime equals p.IdTime
                    join c in db.CRITERION on n.IdCriterion equals c.IdCriterion
                    where n.IdArea == 1 
                    select new ListNotesViewModel { IdCriterion = c.IdCriterion, IdTime = p.IdTime, Notes=n.Note, IdEstudent==e.IdEstudent }).ToList();



     var estu = (from n in db.Qualification
                 join e in db.ESTUDENT on n.IdEstudent equals e.IdEstudent
                 where n.IdArea == 1
                 select e).Distinct().ToList();

     ViewBag.Estudents = estu;
     ViewBag.Time = db.TIME;
     ViewBag.Criterion = db.CRITERION;
     ViewBag.Notes = newItems;

     return View();
 }

相关的视图是:

@{
    ViewBag.Title = "Index";
}

<table border="1">

@foreach (var item4 in ViewBag.Estudents)
{
    <tr>
        <td>
             @item4.CodEstudents - @item4.NameEstudents 
        </td>
         @foreach (var item2 in ViewBag.Time)
         {
             foreach (var item3 in ViewBag.Criterion)
             {
                <td>

                 @if (ViewBag.Notes.IdCriterion == item3.IdCriterion && ViewBag.Notes.IdTime == item2.IdTime && ViewBag.Notes.IdEstudent == item4.IdEstudent)
                 {
                     @ViewBag.Notes.Note 
                 }
                 else
                 {
                     @:nothing
                 }    
               </td>                                                                                                                                                                       

             }
         }

    </tr>
}

</table>

我收到以下错误:

'System.Collections.Generic.List<RolesMVC3.Area.Asesor.Models.ListNotesViewModel>' does not contain a definition for 'IdCriterion'

我无法弄清楚问题是什么。

4

1 回答 1

1

认为这条线导致了它ViewBag.Notes.IdCriterion

@if (ViewBag.Notes.IdCriterion == item3.IdCriterion && ViewBag.Notes.IdTime == item2.IdTime && ViewBag.Notes.IdEstudent == item4.IdEstudent)

ViewBag.Notes是 的集合Note。您需要访问Notes例如ViewBag.Notes[0].IdCriterionViewBag.Notes[i].IdCriterion或中的项目foreach(noteItem in ViewBag.Notes)

于 2012-10-08T05:54:05.290 回答