Question: I am developing MVC application.

I want to get entire object with its child collection when I click on submit button on the form. 

Please check below View Model.

I have below view model.

```
       public class AdviceCreateVM
        {      
            [Key]
            public int Id { get; set; }
            public string AdviceNo { get; set; }
            public  ICollection<InvoiceVM> Invoices { get; set; }
         }

   public class InvoiceVM
    {
        [Key]
        public int Id { get; set; }
        public string InvoiceNumber { get; set; }
        public double TotalAmount { get; set; }
    }

```

Now, I have method create of Paymentadvice controller which accepts the input from view. 

```
    [HttpPost]
    public ActionResult Create(AdviceCreateVM AdviceCreateVM,InvoiceVM invoiceVM)
    {
    }

```

in above menthod, I get the values of Invoice collection in the form of array.

but I have req. that, I should get the Advice create and the Invoice collection only in single object. like below method.

```
    [HttpPost]
    public ActionResult Create(AdviceCreateVM AdviceCreateVM)
    {
    }

```

How to get that ?

Answer: 
When rendering your view, be sure to render out any fields you wish to keep during form submit as a hidden field using something like `Html.HiddenFor()`, if they aren't already represented on the form as an `input`, `select`, `textarea`, etc.

Also when you come to render your repeating element (your invoice), do this in a `for` loop using an index (not a `foreach` loop). Ideally [create an `EditorFor` template](http://coding-in.net/asp-net-mvc-3-how-to-use-editortemplates/) to render the part of the view responsible for entering each `invoice`. Again, ensure any fields you wish to carry across during form submission are rendered as hidden fields.

For example:

```
@Html.HiddenFor(m => m.Id)
@Html.LabelFor(m => m.AdviceNo)
@Html.TextBoxFor(m => m.AdviceNo)

@for (var index = 0; index < Model.Invoices.Count; index++)
{
    @Html.EditorFor(m => m.Invoices[index], "_Invoice")
}

```

The editor template ('\_Invoice', stored in an 'EditTemplates' folder) would be something like:

```
@model InvoiceVM

@Html.HiddenFor(m => m.Id)
@Html.LabelFor(m => m.InvoiceNumber)
@Html.TextBoxFor(m => m.InvoiceNumber)
@Html.LabelFor(m => m.TotalAmount)
@Html.TextBoxFor(m => m.TotalAmount)

```

Using editor for templates will also make working with any MVC validation for child objects easier and will avoid some similar pitfalls.
You can create single ViewModel and add these two classes to that model as its fields

```
public class YourViewModel
    {
       public YourViewModel()
       {
        this.adviceCreateVM = new AdviceCreateVM ();
        this.invoiceVM = new InvoiceVM();
       }

       public AdviceCreateVM adviceCreateVM { get; set; }
       public InvoiceVM  invoiceVM { get; set; }
    }

```

Pass this model to view and return it as

```
[HttpPost]
public ActionResult Create(YourViewModel model)
{
//access both classes as model.adviceCreateVM and model.invoiceVM
}

```