I'm working on an ASP.NET MVC 4
application. I have a view called Currencty.cshtml
and tow methods in my controller:
[HttpGet]
public ActionResult Currency()
{
IEnumerable<Currency> model = unitOfWork.CurrencyRepository.GetAll();
return View(model);
}
[HttpPost]
public ActionResult Currency(IEnumerable<Currency> model)
{
var test = model;
The view itself is :
@model IEnumerable<MyProject.Models.Currency>
@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<table>
<thead>
<tr>
<th rowspan="2">Code</th>
<th rowspan="2">Currency</th>
<th rowspan="2">Fixing</th>
<th colspan="2">PayDesk</th>
<th colspan="2">NoDesk</th>
</tr>
<tr>
<th>Buy</th>
<th>Sell</th>
<th>Buy</th>
<th>Sell</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@Html.HiddenFor(modelItem => item.CurrencyID)
@Html.TextBoxFor(modelItem => item.Code)</td>
<td>@Html.TextBoxFor(modelItem => item.CurrencyName)</td>
<td>@Html.TextBoxFor(modelItem => item.FixingRate)</td>
<td>@Html.TextBoxFor(modelItem => item.PayDeskBuy)</td>
<td>@Html.TextBoxFor(modelItem => item.PayDeskSell)</td>
<td>@Html.TextBoxFor(modelItem => item.NoDeskBuy)</td>
<td>@Html.TextBoxFor(modelItem => item.NoDeskSell)</td>
</tr>
}
</tbody>
</table>
<input type="submit" id="form-submit-button" value="Save" />
}
The problem is that I have a breakpoint in [HttpPost] public ActionResult Currency(IEnumerable<Currency> model)
and I can see that when I submit the form I get there, but the model is always null. Everything seems so straight-forward I just can't see what's going wrong so that I can't get my data back. When I load the form with the [HttpGet]
method everything is OK and I see the data.