Advertisement
Guest User

Untitled

a guest
Jul 16th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. List<Student> StudentList = new List<Student>
  2. {
  3. new Student{ Name = "Handri", Age = 8 },
  4. new Student{Name = "Jon Galloway", Age = 10},
  5. new Student{ Name = "Scott Hanselman", Age = 9}
  6. };
  7.  
  8. public class Teacher
  9. {
  10. public string Name;
  11. public int Age;
  12. }
  13.  
  14. List<Teacher> TeacherList = new List<TeacherList>
  15. {
  16. new TeacherList { Name = "Jhon", Age = 30 },
  17. new TeacherList {Name = "JANE", Age = 25},
  18. new TeacherList { Name = "Peter", Age = 27}
  19. };`
  20.  
  21. @model IEnumerable<Entity.Foo>
  22.  
  23. <table>
  24. <tr>
  25. <th>
  26. @Html.DisplayNameFor(model => model.Bar)
  27. </th>
  28. </tr>
  29.  
  30. @foreach (var item in Model) {
  31. <tr>
  32. <td>
  33. @Html.DisplayFor(modelItem => item.Bar)
  34. </td>
  35. ...
  36.  
  37. return View(StudentList);
  38.  
  39. @model List<Student>
  40. // and property Model is type of List<Student>
  41.  
  42. <table>
  43. @foreach(var student in Model)
  44. {
  45. <tr>
  46. <td>@item.Name</td>
  47. <td>@student.Age</td>
  48. </tr>
  49. }
  50. </table>
  51.  
  52. ViewBag.StudentList = StudentList;
  53.  
  54. @foreach (var item in ViewBag.StudentList)
  55. {
  56. <tr>
  57. <td>@item.Name</td>
  58. <td>@student.Age</td>
  59. </tr>
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement