【发布时间】:2013-03-11 14:42:48
【问题描述】:
我正在尝试创建一个视图,它允许用户使用索引视图模型查看当前列出的项目,然后还允许用户使用单独的创建视图模型创建一个新项目
所以我有两个 viewModel -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 参数在被提交按钮调用时为空。
我做错了什么?
【问题讨论】:
标签: asp.net-mvc partial-views razor-2