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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:51:49+00:00 2026-05-25T02:51:49+00:00

I have a view model which contains an IEnumerable of a child view model.

  • 0

I have a view model which contains an IEnumerable of a child view model. When I create an edit form for the parent and children, then post it, only the parent part of the view model is populated; the IEnumerable property remains null.

The view models:

public class FamilyViewModel 
{

    public int idFamily { get; set; }
    public string FamilyName { get; set; }
public IEnumerable<MemberViewModel> Members { get; set; }

}

public class MemberViewModel 
{

    public int idMember { get; set; }
    public int idFamily { get; set; }
    public string FirstName { get; set; }
}

FamilyController.cs

 [HttpGet]
public ActionResult Edit(int id)
{
    var family = unitOfWork.FamilyRepository.Single(f => f.idFamily == id);
    FamilyViewModel viewModel = Mapper.Map<family, FamilyViewModel>(family);
            /* at this point, viewModel.Members is populated correctly */
    return View(viewModel);
}

[HttpPost]
public ActionResult Edit(FamilyViewModel viewModel)
{
    /* at this point, viewModel.Members is null */
    return View(viewModel);
}

Edit.cshtml:

@model FamilyViewModel

@using (Html.BeginForm())
{
@Html.EditorFor(s => Model, "Family")

@foreach (MemberProfileViewModel m in Model.Members)
{
   @Html.EditorFor(o => m, "Member")
}

@Html.Submit()
}

The form is generated correctly. If I recast the Edit method to use a FormCollection, the values for both Family and each Member are received correctly. However, I’d prefer to use the strongly-typed ViewModel.

One possibly relevant piece of info: each child form control has the same ID ; that is, there are <INPUT TYPE="text" ID="m_FirstName"> for every MemberViewModel — they aren’t indexed in any way, which I would have expected.

  • 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-25T02:51:49+00:00Added an answer on May 25, 2026 at 2:51 am

    I asked a similar question. I put the solution I used in the body of my question. I believe it might be helpful to you as well. By eliminating that foreach the view elements end up being about to be bound back to the underlying viewmodel. Hope that is helpful to you.

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

Sidebar

Related Questions

I have a View that contains a ParentModel, which contains 2 Models. I only
I have the following view model which contains an array of elements function ReservationsViewModel()
I have a complex view model which contains a collection of other objects which
I am using MVC. I have a view model which contains a Business object.
I have a Search Edit view which is strongly typed to my Search model
I have a view that is strongly typed to a view model which contains
I have a view model called ViewModelClass which contains a boolean. I have another
I have two classes (MVC view model) which inherits from one abstract base class.
I have a property in my view model which returns a constant under some
In my application, we have a view model object from which we're retrieving its

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.