Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are getting list from more than two model and want to show two model in one list than you should use like this.. Create your two model first is Student and second is Teacher. </p> <pre><code>// Create Models public class Student { public int Id { get; set; } public string Name { get; set; } public string Address { get; set; } public List&lt;int&gt; Marks { get; set; } } public class Teacher { public int Id { get; set; } public string Name { get; set; } public string Address { get; set; } } </code></pre> <p>//Create controller </p> <pre><code> public ActionResult Index() { List&lt;Student&gt; students = new List&lt;Student&gt;() { new Student {Id = 1, Name = "Vikas", Address = "Mohali", Marks = new List&lt;int&gt; {90, 23, 46,56} }, new Student {Id = 2, Name = "Rajeev", Address = "Mohali", Marks = new List&lt;int&gt; { 56, 78, 34, 67 }}, new Student {Id = 3, Name = "Ajay", Address = "Delhi", Marks = new List&lt;int&gt; {56, 78, 34, 56}} }; List&lt;Teacher&gt; teachers = new List&lt;Teacher&gt;() { new Teacher {Id = 1, Name = "Arun Nagar", Address = "Delhi"}, new Teacher {Id = 2, Name = "Manish Kumar", Address = "Mohali"} }; var Querylist = (from student in students where student.Address == "Mohali" select student.Name) .Concat(from teacher in teachers where teacher.Address == "Mohali" select teacher.Name); //get list in ViewBag ViewBag.DataLIst = Querylist; //get list in View Data ViewData["DataLIst1"] = Querylist.ToList(); return View(Querylist.AsEnumerable()); } //create View "Index.cshtml" @foreach (var h in @ViewBag.DataLIst) { &lt;h3&gt;@h&lt;/h3&gt; } @foreach (var s in @ViewData["DataLIst1"] as List&lt; string&gt;) { &lt;h1&gt;@s&lt;/h1&gt; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload