Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:28:25+00:00 2026-06-07T12:28:25+00:00

This is my model class with two classes Employee and Employee list namespace EditMultiplerecords.Models

  • 0

This is my model class with two classes Employee and Employee list

 namespace EditMultiplerecords.Models
{
    public class Employee
    {

        public int Id { get; set; }
        public string Name { get; set; }
    }
    public class Employeelist : IEnumerable<Employee>
    {
        public List<Employee> employee { get; set; }

        public IEnumerator<Employee> GetEnumerator()
        {
            return employee.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return employee.GetEnumerator();
        }
    }

}

This is my View where i am writing code for editing using javascript

    @model EditMultiplerecords.Models.Employeelist
@{
    ViewBag.Title = "Homepage";
}
<link href="../../Content/StyleSheet1.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">

    $(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();

        });
    });
</script>
@foreach (var item in Model)
{

    using (Html.BeginForm())
    { 
    <div class="editor">
        <p>
            @Html.HiddenFor(x => item.Id)
            @Html.LabelFor(x => item.Name, item.Name)
            @Html.EditorFor(x => item.Name)
            <input type="submit" value="OK" />
        </p>
    </div> 

    }
@*        @Html.Partial("Details", item);*@
}

And this controller class

  public ActionResult Homepage()
    {
        Employeelist el = new Employeelist();
        el.employee = new List<Employee>();
        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);
    }

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:28:28+00:00Added an answer on June 7, 2026 at 12:28 pm

    you need to add @foreach (var item in Model) loop inside using (Html.BeginForm()) to accept modified List

    using (Html.BeginForm())
    {
    
        @foreach (var item in Model)
        { 
        <div class="editor">
            <p>
                @Html.HiddenFor(x => item.Id)
                @Html.LabelFor(x => item.Name, item.Name)
                @Html.EditorFor(x => item.Name)
            </p>
        </div> 
    
        }
    }
           <input type="submit" value="OK" />
    
    @*        @Html.Partial("Details", item);*@
    

    — Edit Accept formCollection

    [HttpPost]
    public ActionResult Homepage(FormCollection formCollection)
    {
        var itemid = formCollection.GetValue("item.id");
        var itemname= formCollection.GetValue("item.name");
    ---//use values to send it back to view----
        return View();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my model class [HiddenInput(DisplayValue = false)] public long ProductId { get; set;
I have two classes: public class DocumentViewModel { public virtual string DocumentNumber { get;
I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
I have two models like this: class OptionsAndFeatures(models.Model): options = models.TextField(blank=True, null=True) entertainment =
I have a two models set up like this: class User < ActiveRecord::Base #
The scenario Suppose I have the following two model classes: public class ProductColor {
Let's say I have the following two classes: package example.model; public class Model {
Suppose there are two classes: class A(models.Model): … class B(models.Model): a = models.ForeignKey(A) …
I have a very simple composite model made of two classes: Public Class ParentModelVM
I have two classes, Portfolio, and PortfolioImage. class PortfolioImage(models.Model): portfolio = models.ForeignKey('Portfolio', related_name='images') ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.