【发布时间】:2013-12-02 11:32:39
【问题描述】:
我正在开发一个ASP.NET MVC 4 应用程序。我的控制器中有一个名为 Currencty.cshtml 的视图和两个方法:
[HttpGet]
public ActionResult Currency()
{
IEnumerable<Currency> model = unitOfWork.CurrencyRepository.GetAll();
return View(model);
}
[HttpPost]
public ActionResult Currency(IEnumerable<Currency> model)
{
var test = model;
视图本身是:
@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" />
}
问题是我在[HttpPost] public ActionResult Currency(IEnumerable<Currency> model) 有一个断点,我可以看到当我提交表单时我到达那里,但模型始终为空。一切看起来都那么简单,我只是看不出出了什么问题,所以我无法取回我的数据。当我使用 [HttpGet] 方法加载表单时,一切正常,我看到了数据。
【问题讨论】:
标签: c# asp.net-mvc-4 razor