我试着做一件很简单的事情,但我试着用正确的方法去做。但我努力想知道什么是最好的。
我有一个流程链,用户必须在其中填写不同表单中的某些字段。有时,它取决于用户输入,下一个显示的是哪个用户的表单。
[HttpGet]
public IActionResult Form1(Form1Vm f1vm)
{
return View(f1vm);
}
[HttpPost]
[ActionName("Form1")]
public IActionResult Form1Post(Form1Vm f1vm)
{
//process the data etc
//prepare the new viewmodel for the next form view (f2vm)
//Option1:
return View("Form2", f2vm);
//Option2:
return RedirectToAction("Form2", f2vm);
//for Option 2 I would need an additional HttpGet Action Method in which I
//would have to call Modelstate.Clear(); in order to not have the
//immediate validation errors on page load
//also all the properties of my viewmodel are passed as get parameters
//what looks pretty nasty for me
}
//More form views action methods should be added here...:
更好的方法是什么?正如我在上面的评论中提到的,对于使用重定向操作选项,我有很大的缺点。但是,如果我使用direct view();call,我不关心
https://en.wikipedia.org/wiki/Post/Redirect/Get
并且用户不能简单地刷新一个页面,而不会得到再次提交表单的警告。
我是不是错过了另一条路,还是看不到明显的东西?
编辑:我只是想到了第三种方法,这是我经常看到的:不将整个虚拟机传输到httpget方法,而是只传输ID。然后我必须从数据库直接加载以前存储的所有数据,再次将其映射到我的新虚拟机,然后调用view();使用这个虚拟机。现在我认为这是“最好的”解决方案,但我觉得这是相当困难的…