I'm trying to pass the values of checkboxs from view to controller. here are my code
In model:
public partial class ORDER_HEADER_INFO
{
//many other fields
public bool checkExport { get; set; }
}
In Controller:
[HttpPost]
public void ExportCSV(List<Models.ORDER_HEADER_INFO> model) {
foreach (Models.ORDER_HEADER_INFO item in model) {
if (item.checkExport) {
//Do somethings
}
}
In View:
@model IEnumerable<TIS.Models.ORDER_HEADER_INFO>
@using (Html.BeginForm("ExportCSV", "MKP_004", FormMethod.Post)){
<input type="submit" value="ExportCSV" />
@foreach (var item in Model)
{DateTime deadline = new DateTime(2015, 04, 12);
var className = (item.PRODUCT_START_DATE >= deadline) ? "selected" : null;
<tr class="@className">
<td>
@Html.ActionLink(item.ORDER_NO, "MKP_003", "MKP_003", new { id = item.ORDER_NO }, new { })
</td>
<td>
@Html.DisplayFor(modelItem => item.MODEL)
</td>
<td>
@Html.DisplayFor(modelItem => item.PJNO)
</td>
<td>
@Html.DisplayFor(modelItem => item.DELIVERY_DESTINATION)
</td>
<td>
@Html.DisplayFor(modelItem => item.PRODUCT_START_DATE)
</td>
<td>
@Html.DisplayFor(modelItem => item.FINISH_FLAG)
</td>
<td>
@Html.CheckBoxFor(modelItem => item.checkExport)
</td>
</tr>
}
</table>
}
My expected outcome is i can get the list of selected items then do some work with them. In parameter of the method. I had tried:
List<Models.ORDER_HEADER_INFO> model
and
IEnumerable<TIS.Models.ORDER_HEADER_INFO> model
but when i debug the model is still null.
Many thanks!