Multiple model pass in MVC using tuple or Tuple in MVC

Controller Code

public ActionResult IndexTuple() 

    ViewBag.Message = "Welcome to my demo!"; 
    var tupleModel = new Tuple<List<Teacher>, List<Student>>(GetTeachers(), GetStudents()); 
    return View(tupleModel); 
}

View Code

@using MultipleModelInOneView; 
@model Tuple <List<Teacher>, List <Student>> 
@{ 
    ViewBag.Title = "Home Page"; 

<h2>@ViewBag.Message</h2> 
<p><b>Teacher List</b></p> 
<table> 
    <tr> 
        <th>Id</th> 
        <th>Code</th> 
        <th>Name</th> 
    </tr> 
    @foreach (Teacher teacher in Model.Item1) 
    { 
        <tr> 
            <td>@teacher.TeacherId</td> 
            <td>@teacher.Code</td> 
            <td>@teacher.Name</td> 
        </tr> 
    } 
</table> 
<p><b>Student List</b></p> 
<table> 
    <tr> 
        <th>Id</th> 
        <th>Code</th> 
        <th>Name</th> 
        <th>Enrollment No</th> 
    </tr> 
    @foreach (Student student in Model.Item2) 
    { 
        <tr> 
            <td>@student.StudentId</td> 
            <td>@student.Code</td> 
            <td>@student.Name</td> 
            <td>@student.EnrollmentNo</td> 
        </tr> 
    } 
</table>  

Comments

Popular posts from this blog

SECURING WEBAPI USING JSON WEB TOKEN (JWT) IN WEB API C#

Adding ASP.NET MVC5 Identity Authentication to an existing project