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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:07:02+00:00 2026-05-21T22:07:02+00:00

In an mvc 3 .Net FW 4.0 project I have a data that relates

  • 0

In an mvc 3 .Net FW 4.0 project I have a data that relates in a parent child relationship, I’ve built up my model to contain a list of “children” with each parent record, and displaying it as in the following example:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/ViewMasterPage.Master" Inherits="System.Web.Mvc.ViewPage<MvcTest.Models.ModelList>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    ShowPropReturn
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>ShowPropReturn</h2>

<script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>

<% using (Html.BeginForm()) { %>
    <%: Html.ValidationSummary(true) %>
    <fieldset>
        <legend>ModelList</legend>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.MyProperty1) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.MyProperty1) %>
            <%: Html.ValidationMessageFor(model => model.MyProperty1) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.MyProperty2) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.MyProperty2) %>
            <%: Html.ValidationMessageFor(model => model.MyProperty2) %>
        </div>

        <table>
        <% foreach (var item in Model.MyProperty3)
           { %>
                <tr>
                    <td>
                        <%: Html.TextBoxFor(i => item.string1) %>
                    </td>
                    <td>
                        <%: Html.TextBoxFor(i => item.string2) %>
                    </td>
                </tr>

        <% } %>
        </table>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
<% } %>

<div>
    <%: Html.ActionLink("Back to List", "Index") %>
</div>

</asp:Content>

I figured out that if a displayfor is used to only display a field value, it does not get posted back which makes sense. But I’m getting a null for the child list object in the model on httppost and I need to have these items edited on the same view, it is also null in the formcollection object, can anyone help me on this please?

  • 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-21T22:07:03+00:00Added an answer on May 21, 2026 at 10:07 pm

    Instead of the foreach loop try using an editor template:

    <table>
        <%= Html.EditorFor(x => x.MyProperty3)
    </table>
    

    and inside the corresponding editor template (~/Views/Shared/EditorTemplates/SomeModelType.ascx):

    <%@ Control Language="C#" 
        Inherits="System.Web.Mvc.ViewUserControl<AppName.SomeModelType>" 
    %>
    <tr>
        <td>
            <%= Html.TextBoxFor(x => x.string1) %>
        </td>
        <td>
            <%= Html.TextBoxFor(x => x.string2) %>
        </td>
    </tr>
    

    Now this will generate proper input field names so that when you submit the form values will be correctly bound.

    Remark: In this case I assume that MyProperty3 on your main view model is defined like this (a collection of SomeModelType):

    public IEnumerable<SomeModelType> MyProperty3 { get; set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC project with xVal and data annotations and I need
I have an ASP.NET MVC project and I have a single action that accepts
I have an ASP.NET MVC project with a form. In the Action method that
We have an ASP.Net MVC project that will start with a single web server
I have an Asp.net MVC project that modestly uses jQuery scripts. My views also
in my asp.net MVC project i have an database connection with connectionstring: Data Source=.;Initial
I have an existing ASP.Net MVC project that is using entities / repositories in
I have an ASP.NET MVC 3 project that I just created using the project
I have an ASP.NET MVC 2 project in which I've created a data transfer
i have project in ASP.NET MVC 3 and a mysql database that contains a

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.