Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The content of temp view should be something as follows:</p> <pre><code>&lt;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage&lt;IEnumerable&lt;MvcApplication1.Models.Student&gt;&gt;" %&gt; &lt;table&gt; &lt;% foreach (var item in Model) { %&gt; &lt;tr&gt; &lt;td&gt; &lt;%= Html.Encode(item.Id) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= Html.Encode(item.FirstName) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= Html.Encode(item.LastName) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= Html.Encode(item.Age) %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;% } %&gt; &lt;/table&gt; </code></pre> <p>The edit view content:</p> <pre><code>&lt;% using (Html.BeginForm()) { %&gt; &lt;fieldset&gt; &lt;% foreach (Student s in Model) { %&gt; &lt;%= Html.Hidden("Id", s.Id)%&gt; &lt;p&gt; &lt;span&gt;First Name&lt;/span&gt;&lt;br /&gt; &lt;%= Html.TextBox("FirstName", s.FirstName)%&gt; &lt;/p&gt; &lt;p&gt; &lt;span&gt;Last Name&lt;/span&gt;&lt;br /&gt; &lt;%= Html.TextBox("LastName", s.LastName)%&gt; &lt;/p&gt; &lt;p&gt; &lt;span&gt;Age&lt;/span&gt;&lt;br /&gt; &lt;%= Html.TextBox("Age", s.Age)%&gt; &lt;/p&gt; &lt;hr /&gt; &lt;% } %&gt; &lt;input type="submit" value="Submit" /&gt; &lt;/fieldset&gt; &lt;% } %&gt; </code></pre> <p>The student class structure:</p> <pre><code>namespace MvcApplication1.Models { public class Student { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } } </code></pre> <p>Lastly, the controller:</p> <pre><code>using System.Collections.Generic; using System.Web.Mvc; using MvcApplication1.Models; namespace MvcApplication1.Controllers { public class HomeController : Controller { public ActionResult Index() { List&lt;Student&gt; students = new List&lt;Student&gt;(); // Fill with dummy data for test. students.Add(new Student { Id = 1, FirstName = "X", LastName = "X", Age = 20 }); students.Add(new Student { Id = 2, FirstName = "Y", LastName = "Y", Age = 30 }); return View(students); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(int[] id, string[] firstName, string[] lastName, int[] age) { List&lt;Student&gt; students = new List&lt;Student&gt;(); for (int i = 0; i &lt; id.Length; i++) { students.Add(new Student { Id = id[i], FirstName = firstName[i], LastName = lastName[i], Age = age[i] }); } return View("Shows", students); } } } </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.
 

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