ASP.NET MVC - TempData的 - 是好是坏的做法 [英] ASP.NET MVC - TempData - Good or bad practice

查看:174
本文介绍了ASP.NET MVC - TempData的 - 是好是坏的做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用在斯科特谷的preVIEW 5博客文章的详细处理在ASP.NET MVC的形式条目 AcceptVerbs 方法:

I'm using the AcceptVerbs method detailed in Scott Gu's Preview 5 blog post for dealing with form entries in ASP.NET MVC:


  • 用户通过GET得到一个空的形式

  • 用户职位通过POST填写表格相同的动作

  • 行动验证数据,采取相应的操作,并重定向到一个新的视图

所以我没有使用的TempData 。这就是说,我现在有一个确认一步到这个过程中,它似乎需要使用的TempData

So I don't have to use TempData. That said, I now have to add a 'confirm' step to this process, and it seems to require the use of TempData.

由于某些原因,我讨厌使用的TempData - 这是值得各地设计

For some reason, I have an aversion to using TempData -- that it is something to be designed around.

这是在所有有效的关注,还是我补差?

Is this at all a valid concern, or am I making it up?

推荐答案

我有种想临时数据为用于通知用户一个发射后不管的机制。它的伟大,给他们的东西,他们最近做了一个提醒,但我还犹豫,使其在一些用户进程的必要步骤。是,如果他们刷新页面,我相信它的理由也就不复存在了。嗯,我想我也不敢随便使用它作为其没有真正明确它是多么可靠。

I kind of think of temp data as being a fire-and-forget mechanism for notifying the user. Its great to give them a reminder of something they recently did, but I'd also be hesitant to make it a required step in some user process. The reason being if they refresh the page, I believe it would be gone. Well I guess I'm also hesitant to use it as its not really well defined how reliable it is.

我想知道的问题是,您所遇到的行为重定向到另一页的确认步骤之前。我不知道他们第一次提交后,而不是,你可以做足够的处理,生成确认对话框,然后确认问题回到原来的页面。类似的方法可以完成验证,除了验证规则检查是否进行了确认步骤(与隐藏,直到其他验证通过的确认UI)。

I wonder if the problem is that you're having the action redirect to another page before the confirm step. I wonder if instead after they first submit, you could do enough processing to generate the confirm dialog, then return the original page with the confirm question. Similar to how you might do validation, except the validation rule checks whether the confirmation step was performed (with the confirmation UI hidden until other validation passes).

这篇关于ASP.NET MVC - TempData的 - 是好是坏的做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆