您可以在第二个视图中使用隐藏字段,该字段将包含在第一个视图中输入的项目名称。这样,当您提交第二个表单时,您将获得项目名称和项目文件夹。
另一种可能性是将在第一个视图中输入的值存储在服务器某处(数据库、会话...)
更新:
作为 cmets 部分的请求,这里是一个使用隐藏字段的示例。
第一个视图:
@model FirstStepViewModel
@using (Html.BeginForm())
{
@Html.EditorFor(x => x.ProjectName)
<button type="submit">OK</button>
}
然后是这个第一步将被提交到的控制器操作:
[HttpPost]
public ActionResult Foo(FirstStepViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
return RedirectToAction("Bar", new { projectname = model.ProjectName });
}
然后您将拥有第二个控制器操作,该操作将为第二个视图提供服务:
public ActionResult Bar(FirstStepViewModel firstStep)
{
var model = new SecondStepViewModel
{
ProjectName = firstStep.ProjectName
};
return View(model);
}
然后你就会有一个对应的视图:
@model SecondStepViewModel
@using (Html.BeginForm())
{
@Html.HiddenFor(x => x.ProjectName)
@Html.EditorFor(x => x.ProjectFolder)
<button type="submit">OK</button>
}
将发布到最终操作:
[HttpPost]
public ActionResult Bar(SecondStepViewModel model)
{
// here you will get both model.ProjectName and model.ProjectFolder
...
}