I have a very simple datatable that returns:
Report1 and a checkbox Report2 and a checkbox
here is my view:
@model GRM_Reports.Models.ReportsModel
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("Index","Report", FormMethod.Post))
{
<table>
<tr style="font-weight:bold">
<td>
Report Name
</td>
<td>
Number Of Rows
</td>
<td>
Number Of Errors
</td>
<td>
Run Report
</td>
</tr>
@foreach (var report in Model.ReportList)
{
<tr>
<td>
@Html.DisplayFor(modeltem => report.ReportName)
</td>
<td>
@Html.DisplayFor(modeltem => report.NumberOfRows)
</td>
<td>
@Html.DisplayFor(modeltem => report.NumberOfErrors)
</td>
<td>
@Html.CheckBoxFor(modeltem => report.checkBox)
</td>
</tr>
}
<tr>
<td colspan="4">
<button type="submit" >Submit Request</button>
</td>
</tr>
</table>
}
when I click the submit button the ReportList is null.
namespace GRM_Reports.Controllers
{
public class ReportController : Controller
{
public ActionResult Index()
{
var model = new ReportsModel();
Database db = new Database();
DataTable dt = new DataTable();
dt = db.GetReportStatus("1/31/2014");
model.ReportList = new List<Models.Common.Report>();
foreach (DataRow row in dt.Rows)
{
model.ReportList.Add(
new Models.Common.Report()
{ ReportName = row["Report"].ToString(),
NumberOfRows = int.Parse(row["NumberOfRows"].ToString()),
NumberOfErrors = int.Parse(row["NumberOfErrors"].ToString()),
HasData = row["hasData"].ToString()
});
}
return View(model);
}
[HttpPost]
public ActionResult Index(ReportsModel model)
{
foreach (var report in model.ReportList)
{
}
return View();
}
}
}
I think there is a problem with this method: [HttpPost] public ActionResult Index(ReportsModel model)
The model that is passed to this method is null. Any ideas?
Thank you.

