title: Any better way to post list of object of class on controller
body: <p>I want to post my list of object to my controller.</p>
  
  <p>This is my class file:</p>
  
  <pre><code> public class MyModel
      {
          public int Id {get; set;}
          public List&lt;ChildModel&gt; ChildModelObject{ get; set; }
      }
  
  public class ChildModel
      {
          public int ChildId {get; set;}
          public int sum {get; set;}
      }
  </code></pre>
  
  <p>My View Page:</p>
  
  <pre><code> @model Demo.MyModel
  
        @using (Html.BeginForm())
          {
            @{ int i = 0; }
            @foreach (var item in Model.ChildModelObject) //first I am displaying value and then on submit i will post this value
             {
                &lt;input type="hidden" name="@Html.Raw("ChildModelObject[" + i + "].ChildId")" value="@item.ChildId" /&gt; //This is how i am taking value and it is working perfect and i am getting childid.
               @Html.DisplayFor(modelItem =&gt; item.sum)
             }
  &lt;input type="submit" value="Save"/&gt;
          }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code> public ActionResult Index(MyModel model)//In this i want all childid when form is posted
          {
          }
  </code></pre>
  
  <p>So now when i click on submit button then i want all <strong>childid</strong> in my <strong>MyModel</strong> object.</p>
  
  <p>Can anybody tell me any better approach then what i am doing??</p>