0

I'm trying to create a set of views to gather a lot of information. I say set because I have broken up this information across several pages, organized by the type of questions. I want the user to be able to leave and add, remove, update data as they wish, but I also need them to be able to cancel their changes. Seems simple enough.

But conceptualizing this from a code point of view, I'm having issues.

At first I wanted to preserve the model across multiple pages. So I would have a controller that redirects to different views depending on the step they have and pass the model around until they saved. However, unless I store all the information they aren't currently working on in hidden fields, the model I return from the view to go to the next step is half empty.

I then considered working with session variables. I then figured that if I pressed the back button or left the "workflow" without clicking cancel to clear the session variable, then I risk a user reopening the same object and their changes still be there.

I don't really see an elegant way of doing this. I assume this is my lack of ASP.NET\MVC experience.

4

1 回答 1

0

我们在我工作的地方做类似的事情,那里有一个向导类型的界面,每一步都是它自己的视图。目前,我们已启用 session 以在步骤之间保存顶级模型,但这对我们来说是暂时的。为了避免会话的开销(请求生命周期和状态服务器的网络流量),我们可能很快会切换到将顶级模型作为 JSON 持久化到数据库表(以及用户的密钥),未来,我们可能会为模型中的数据构建强类型存储表,以便更轻松地查询/报告进程中的用户。这也使我们能够控制数据的生命周期,并且用户可以在下次登录时从上次中断的地方继续。MVC 纯粹主义者似乎说不使用 ASP.net 会话状态,但我不确定为什么。这可能是因为通过使用会话,您不再是 REST-ful,而是 MVC != REST(尽管它可以)。我想说,如果您时间紧迫,启用会话状态并将数据扔在那里可以让您更快地完成它。您可以随时更改它,就像我的团队计划做的那样。这里的真正答案也取决于您的业务需求。无论如何,希望这会为这个问题增加一些有用的东西。

于 2013-08-02T20:46:12.503 回答