【发布时间】:2010-03-30 17:32:59
【问题描述】:
我在表单中使用incremental sequencing for a collection of objects。除非我需要使用 DropDownListFor,否则一切正常。很多questions concerning binding a dropdown 并选择正确的值,这在我的情况下工作正常。但是,我不清楚控制器中的 HttpPost 操作应该有什么。这是我的代码:
型号
public class WorkRequestList
{
public WorkRequest[] Requests { get; set; }
public Vehicle[] Vehicles { get; set; }
}
查看
<% using (Html.BeginForm()) {%>
<% for (var i = 0; i < Model.Requests.Count(); i++) { %>
<%=Html.DropDownListFor(x => x.Requests[i].AssignedTo,new SelectList(Model.Vehicles,"Id","Name",Model.Requests[i].AssignedTo.Id)) %>
<%}%>
<%=Html.SubmitButton("TopSubmit","Submit") %>
<%}%>
发布的操作
[HttpPost]
public ActionResult Schedule(WorkRequestList form)
{
//what goes here?
}
下拉列表可以很好地填充,它们可以很好地预先选择。但在回发 form.Requests.AssignedTo 为空。我假设车辆 ID 被发布回某处,但我如何在不通过 Request 魔术字符串循环的情况下实现这一点:
var id = Request["Requests[" + i + "].AssignedTo"];
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-2 html.dropdownlistfor