Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC4 application on handling list
    primarykey
    data
    text
    <p>This is my model class with two classes Employee and Employee list</p> <pre><code> namespace EditMultiplerecords.Models { public class Employee { public int Id { get; set; } public string Name { get; set; } } public class Employeelist : IEnumerable&lt;Employee&gt; { public List&lt;Employee&gt; employee { get; set; } public IEnumerator&lt;Employee&gt; GetEnumerator() { return employee.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return employee.GetEnumerator(); } } } </code></pre> <p>This is my View where i am writing code for editing using javascript</p> <pre><code> @model EditMultiplerecords.Models.Employeelist @{ ViewBag.Title = "Homepage"; } &lt;link href="../../Content/StyleSheet1.css" rel="stylesheet" type="text/css" /&gt; &lt;script src="../../Scripts/jquery-1.6.2.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function () { $('.editor input').blur(function () { $(this).hide(); $(this).closest('p').find('label').html($(this).val()).show(); }); $('.editor label').click(function () { $(this).hide(); $(this).closest('p').find('input').show(); }); }); &lt;/script&gt; @foreach (var item in Model) { using (Html.BeginForm()) { &lt;div class="editor"&gt; &lt;p&gt; @Html.HiddenFor(x =&gt; item.Id) @Html.LabelFor(x =&gt; item.Name, item.Name) @Html.EditorFor(x =&gt; item.Name) &lt;input type="submit" value="OK" /&gt; &lt;/p&gt; &lt;/div&gt; } @* @Html.Partial("Details", item);*@ } </code></pre> <p>And this controller class</p> <pre><code> public ActionResult Homepage() { Employeelist el = new Employeelist(); el.employee = new List&lt;Employee&gt;(); el.employee.Add(new Employee { Id = 1, Name = "Rahul" }); el.employee.Add(new Employee { Id = 2, Name = "America" }); el.employee.Add(new Employee { Id = 3, Name = "NewJersey" }); return View(el); } [HttpPost] public ActionResult Homepage(Employeelist el) { return View(el); } </code></pre> <p>My problem is when i edit Rahul or America or NewJersey, on Post Action iam getting an empty list with null values rather an updated list </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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