0

i have the next view:

@model IEnumerable<L5ERP.Model.BLL.BusinessObjects.MTR_MonthlyTransfer>
@using (Html.BeginForm("ExpenseMonthlyTransferProcessing", "BudgetTransfer", Model.ToList())){
<table class ="divTable">
<tr>
    <th>Transferir</th>

    <th>
       Clave
    </th>

    <th>
        Monto
    </th>

</tr> 
@foreach (var item in Model) {
<tr>
    <td>
        @Html.CheckBoxFor(x => item.MTR_Bool, new { @class = "checkMTR", @checked = "checked" })

    </td>
    <td>
         @Html.TextBoxFor(x => item.MTR_Key, new {@class = "longInput" })
    </td>
    <td>
        @String.Format("{0:F}", item.MTR_Amount)
    </td>
</tr>   
 } 
</table> 
}

and my controller like this

[HttpPost]
    public ActionResult ExpenseMonthlyTransferProcessing(List<MTR_MonthlyTransfer> lstMtr)
    { return View(lstMTR); }

But when i do the post my list is null, how can i send my list through the submit button ?

Lio
  • 5
  • 1
  • 3
  • 5

2 Answers2

1

You should change the @model to an array (L5ERP.Model.BLL.BusinessObjects.MTR_MonthlyTransfer[]) or something else that implements IList<>:

@model L5ERP.Model.BLL.BusinessObjects.MTR_MonthlyTransfer[]

@for (var i = 0; i < Model.Length; i ++) {
<tr>
    <td>
        @Html.CheckBoxFor(x => Model[i].MTR_Bool, new { @class = "checkMTR", @checked = "checked" })
    </td>
    <td>
        @Html.TextBoxFor(x => Model[i].MTR_Key, new {@class = "longInput" })
    </td>
    <td>
        @String.Format("{0:F}", item.MTR_Amount)
    </td>
</tr> 
Ed Chapel
  • 6,842
  • 3
  • 30
  • 44
  • Ed is referring to the fact that you need to index the names for the modelbinder. when his example renders the MTR_Key textbox would look like This enables the modelbinder to know which element in the array each input belongs to. Alternately, submitting it as an array of json objects should work. – Chad Ruppert Sep 04 '12 at 02:33
0

receive a FormCollection and parse the items in it manually

Use F12 to check the post in your navigator to see if it are sending the content you expected.

Alberto León
  • 2,879
  • 2
  • 25
  • 24
  • I fill my table with a FOR instead a FOREACH but my i use a .ToList in mi Model, now doing this i can access to de indexs of my collection. here's the code of my view: @for (int i = 0; i < Model.ToList().Count; i++){ } This works ;) !
    Transferir Clave Monto
    @Html.TextBoxFor(x => Model.ToList()[i].MTR_Key)
    – Lio Sep 03 '12 at 23:22