查询ViewData,然后根据结果更改值

时间:2017-10-12 17:03:00

标签: asp.net-mvc

我的控制器中有这段代码

outputmodel4.Add(new SP_data.student()
                {
                    student_id = (decimal)SPOutput4["student_id"],
                    student_no = (string)SPOutput4["student_no"],
                    course_id = (decimal)SPOutput4["course_id"],
                    floor_no = (int)SPOutput4["floor_no"],
                    tutor_id = (decimal)SPOutput4["tutor_id"],
                    capacity_id = (decimal)SPOutput4["capacity_id"],
                });

            }
            ViewData["Output"] = outputmodel4;

我正在尝试查询Capacity_id,如果数字是(比方说)2,则在我的视图中显示“All Most Full”。

我认为实现这一目标的意思是

@foreach (var item in ViewData["Output"] as IEnumerable<app.Models.SP_data.student>)
  {
  <TD>
  @if (item.capacity_id = 2)
   {
     All Most Full
   }
   else if (item.capacity_id = 5)
   {
     Full
   }
    else if    etc..
  </TD>
}

..但我在视图中收到错误

  

无法将类型十进制隐式转换为bool

有人可以提供建议和帮助吗?

感谢

0 个答案:

没有答案
相关问题