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 6898585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:18:54+00:00 2026-05-27T07:18:54+00:00

I have a situation where I need to edit an enumerable property in a

  • 0

I have a situation where I need to edit an enumerable property in a view model:

public class ViewModel
{
    public MyObj Obj { get; set; }
    public IEnumerable<MyObj> MyObjs = new List<MyObj>();
}

I have followed this post; controller action:

public ActionResult Index()
{
    var viewModel = new ViewModel();
    viewModel.Obj = new Obj() { Name = "0", Value = true };
    var o1 = new MyObj() { Name = "1", Value = false };
    var o2 = new MyObj() { Name = "2", Value = false };
    viewModel.Objs = new List<Obj>() { o1, o2 };

    return View(viewModel);
}

[HttpPost]
public ActionResult Index(ViewModel viewModel)
{
    return View(viewModel);
}

The Index view as follows:

<% using (Html.BeginForm()) { %>

    <table>
        <tr>
            <th>Name</th>
            <th>Value</th>
        </tr>
        <%= Html.EditorFor(x => x.Objs) %>
    </table>

    <br />

    <input type="submit" value="Submit" />

<% } %>

And the editor template in “~/Views/Home/EditorTemplates/Obj.ascx”:

    <tr>
        <td><%: Html.TextBoxFor(x => x.Name) %></td>
        <td><%: Html.CheckBoxFor(x => x.Value) %></td>
    </tr>

The issue is: browse to Index, the data shows up. The POST, and the enumerable data disappears. Stepping through, the singular “Obj” in the view model remains, so it is just the enumerable data that is disappearing.

I have been staring at this for some time now, if any one could help out it would be brilliant.

Cheers,

Tim.

  • 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-05-27T07:18:55+00:00Added an answer on May 27, 2026 at 7:18 am

    Take a look at this post by Phil Haack, MVC2 doesn’t natively support binding a list back to the viewmodel unless you do a little manipulation.

    Update: I’ve looked into this a little more and think you should try adding TryUpdateModel(viewModel.MyObjs, "MyObjs"); to your Controller. This informs the modelbinder that it should use the “MyObjs” binding prefix to attach the data from the form to the collection in your ViewModel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where i need to set SelectedIndex of my combobox to
Ok, so I have the following situation. I need to edit the PYTHONPATH dynamically
I have a situation where I need to programmatically set something that has a
I have situation where I need to change the order of the columns/adding new
I have a situation where I need to initialize/assign variables from the results of
I have a situation where I need to be able to load assemblies in
I have a situation where I need to work with a datagrid and adding
I have a situation where i need to debug a Windows CE application in
I have a situation where I need to update a control referenced in a
I have a situation where I need to notify some users when something in

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.