我想在我的视图中通过POST向我的控制器发送一个IEnumerable(ICustomModel)。这是我的观点
@model IEnumerable<string>
@{
//This just gets me a Dictionary of <Views,Models> that I will use to render partal views,
var forms = CustomFormUtil.GetCustomMetaPartial2(Model);
//List of models I want to send to my Controller via Post
var result = forms.Select(x => x.Model);
}
//I am sendind the IE<ICustomModels>
@using (Html.BeginForm(MVC.Service.NewOrderRequest.Index(result), FormMethod.Post))
{
foreach (var form in forms)
{
{ Html.RenderPartial(form.View, form.Model); }
}
<p style="clear: both">
<input id="submitNOR" type="submit" value="Submit" style="float: right" />
</p>
}
我的控制器如下
[HttpPost]
[SaveModelState]
public virtual RedirectToRouteResult Index(IEnumerable<ICustomMetaModel> forms)
{
if (!ModelState.IsValid)
{
ModelState.AddModelError("error", "Please fill out the required fields");
return RedirectToAction(MVC.Service.NewOrderRequestForms.Index());
}
...
调试我可以在控制器中看到他正在接收正确的数据,但是当我点击提交时,会收到0的值。
我对这种行为感到很困惑。 这是将多个模型传递给Controller的最佳方法吗? 谢谢