Problem - List binding gets null
My View
- @model List<WebApplication5.Models.Site>
- @{
- ViewBag.Title = "Home Page";
- int i = 0;
- int j = 0;
- }
- @using (Html.BeginForm("Index", "Home", FormMethod.Post))
- {
- <table class="table">
-
- @foreach (var item in Model)
- {
- <tr>
- <td>
- @Html.Hidden("ItemSiteCosting.Index", (@i + 10))
- @Html.TextBox("ItemSiteCosting[" + (@i + 10) + "].name", Model[i].name)
- @item.name
- </td>
- <td>
- <table class="table">
- @{ j = 0;}
- @foreach (var item2 in item.xyz.costing.Sitecosting)
- {
-
- <tr>
- <td>
- @Html.TextBox("ItemSiteCosting[" + (@i + 10) + "].xyz.costing.Sitecosting[" + (@j + 10) + "].Amount", Model[i].xyz.costing.Sitecosting[j].Amount)
- @item2.Amount
-
- </td>
- </tr>
- j = j + 1;
- }
- </table>
- </td>
- </tr>
- i = i + 1;
- }
-
- </table>
- <input type="submit" value="Submit" />
- }
My models
- public class Site
- {
- public string name { get; set; }
- public BestPO xyz { get; set; }
- }
-
- public class BestPO
- {
- public BestPO()
- {
- costing = new SiteCost();
- }
- public string Cost { get; set; }
- public SiteCost costing { get; set; }
-
- }
-
- public class SiteCost
- {
- public SiteCost()
- {
- Sitecosting = new List<Money>();
- }
- public string Name { get; set; }
- public List<Money> Sitecosting {get;set;}
-
- }
-
- public class Money
- {
- public decimal? Amount { get; set; }
-
- }