我只是在阅读这个帖子:MVC How to pass a list of objects with List Items POST action method
控制器 - 获取方法
public ActionResult CheckStep1(int id)
{
var vm = new List<CheckStep>();
return View(vm);
}
但我的控制器总是接收参数为null
[HttpPost]
public ActionResult CheckStep1(ICollection<CheckStep> model)
{
//TODO - here models is null
return RedirectToAction("Index");
}
视图
@using (Html.BeginForm(Html.BeginForm("CheckStep1", "MyController", FormMethod.Post)))
{
@Html.ValidationSummary(true)
@for (var i = 0; i < Model.CheckStep.Count; i++)
{
<tr>
<td>
@Html.EditorFor(x => x.CheckStep[i].Id)
</td>
<td>
@Html.EditorFor(x => x.CheckStep[i].name)
</td>
</tr>
}
})
我检查了我的fiddler
并且所有参数都在URL中,但由于某种原因,控制器总是获得空值
fiddler log
POST http://localhost:5773/MyController/CheckStep1/1 HTTP/1.1
Host: localhost:5773
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://localhost:5773/MyController/CheckStep1/1
Content-Length: 5205
model.Id=1&model.name=Jonh&model.Id=2&model.name=Kath