0
我在表单中使用incremental sequencing for a collection of objects。除了当我需要使用DropDownListFor时,所有的工作都很好,并且很漂亮。很多questions concerning binding a dropdown和选择正确的值,这在我的情况下工作正常。然而,我不清楚应该在我的控制器中的HttpPost动作。这里是我的代码:递增排序DropDownListFor绑定?
型号
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?
}
的dropdo列表填充得很好,他们得到预选就好了。但在发表回复form.Requests.AssignedTo为空。我假设车辆ID被调回地方,但我如何才能到,而不诉诸通过Request
魔术字符串循环:
var id = Request["Requests[" + i + "].AssignedTo"];
我写了一个巨大的丑陋模型绑定器,我正在使用。这看起来像一个更好的方法,会尝试一下。 – mxmissile 2010-03-31 13:41:58
这太酷了,谢谢,让MVC变得更加简单。 – mxmissile 2010-03-31 14:53:32