我正在尝试创建一个视图,它允许用户使用索引视图模型查看当前列出的项目,然后还允许用户使用单独的创建视图模型创建一个新项目
所以我有两个视图模型 -IndexFunkyThingsViewModel -CreateFunkyThingViewModel
本质上,我有一个主要观点:
@model IndexFunkyThingsViewModel
@foreach (var item in Model.FunkyThings)
{
/*Indexy stuff*/
}
/*If create item*/
@if (Model.CreateFunkyThing)
{
@Html.Partial("_CreateFunkyThingPartial", new CreateFunkyThingViewModel());
}
然后在我的部分观点中,我有
@model CreateFunkyThingViewModel
@using (Html.BeginForm(MVC.FunkyThings.CreateFunkyThing(Model)))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Create FunkyThing</legend>
@Html.EditorForModel();
<p>
<input type="submit" class="button green" value="CreateFunkyThing" />
</p>
</fieldset>
}
最后在控制器中我有:
[HttpPost]
public virtual ActionResult CreateFunkyThing(CreateFunkyThingViewModel createFunkyThingViewModel)
{
..
}
这一切似乎编译得很愉快,当我进入视图时,它可以显示创建字段等。然而,当我点击提交按钮时,控制器没有收到任何数据。ActionResult 被调用,但是在调试器中,createFunkyThingViewModel 参数在被提交按钮调用时为空。
我究竟做错了什么?