在视图中使用Html.BeginForm()方法时,需注意传递的参数。如果表单中有列表需要传递给控制器,应该使用Html.ListBox()或者Html.DropDownList()方法来生成列表控件,并将其包含在Html.BeginForm()中。例如:
@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post))
{
@Html.ListBox("SelectedItems", Model.MyList)
}
在控制器中,通过相应的参数名称来接收所传递的列表。例如:
[HttpPost]
public ActionResult ActionName(List SelectedItems)
{
// code to process list items
}