Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Student> StudentList = new List<Student>
- {
- new Student{ Name = "Handri", Age = 8 },
- new Student{Name = "Jon Galloway", Age = 10},
- new Student{ Name = "Scott Hanselman", Age = 9}
- };
- public class Teacher
- {
- public string Name;
- public int Age;
- }
- List<Teacher> TeacherList = new List<TeacherList>
- {
- new TeacherList { Name = "Jhon", Age = 30 },
- new TeacherList {Name = "JANE", Age = 25},
- new TeacherList { Name = "Peter", Age = 27}
- };`
- @model IEnumerable<Entity.Foo>
- <table>
- <tr>
- <th>
- @Html.DisplayNameFor(model => model.Bar)
- </th>
- </tr>
- @foreach (var item in Model) {
- <tr>
- <td>
- @Html.DisplayFor(modelItem => item.Bar)
- </td>
- ...
- return View(StudentList);
- @model List<Student>
- // and property Model is type of List<Student>
- <table>
- @foreach(var student in Model)
- {
- <tr>
- <td>@item.Name</td>
- <td>@student.Age</td>
- </tr>
- }
- </table>
- ViewBag.StudentList = StudentList;
- @foreach (var item in ViewBag.StudentList)
- {
- <tr>
- <td>@item.Name</td>
- <td>@student.Age</td>
- </tr>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement