- 可以在视图中引用命名空间,在后面就可以直接调用该命名空间中的类
-
@using TEST.Models; //List<Test.Models.Students> listStudents=new List<Test.Models.Students>(); list<Students>=new List<Students>();//直接调用
代码块
@{ UserInfo currentUserInfo = Session["userinfo"] as UserInfo; List<Students> listStu = ViewData["listStu"] as List<Students>;//ViewData在使用时需要类型转换 }
<table> @{ foreach (Students item in listStu) { <tr> <td>@item.StuNo</td> <td>@item.StuName</td> <td>@item.ClassId</td> <td>@item.Sex</td> <td>@item.Telephone</td> <td>@item.Birthday</td> <td><a href="#">查看</a></td> <td><a href="#">修改</a></td> <td><a href="#">删除</a></td> </tr> } } </table>
@(表达式)
-
value="@(ViewBag.Id!=null?ViewBag.Id:"")"
注释语句
-
@* 被注释语句 *@
转义字符
@@163.com //@163.com