ASP MVC中是否有等效的JSF @ViewScope? [英] Is there an equivalent of JSF @ViewScope in ASP MVC?

查看:62
本文介绍了ASP MVC中是否有等效的JSF @ViewScope?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在ASP MVC 3中开发的应用程序中,我有以下情形.我具有要在页面发出请求后使用的模型的某些属性,但是在完成发布请求后,它们将以null形式到达,因为它们未绑定到视图表单中的任何控件.

In the application I'm developing in ASP MVC 3 I have the following scenario. I have some properties of the model that I wanna use after the page makes a request, however when the post request is done they arrive as null since they are not bound to any control in the view form.

对于我所读的内容,这是ASP MVC的预期行为,人们建议使用@ Html.HiddenFor()来接收它们,但我不希望该信息可供用户使用.他从浏览器中选择查看源代码".

For what I've read this is the expected behaviour of ASP MVC and people recommend to use a @Html.HiddenFor() to be able to receive them, but I don't want this information to be available to user in case he selects "View source" from the browser.

在JSF中,我记得您可以在这种情况下使用@ViewScope批注,但是ASP MVC中有类似的东西吗?对于我已阅读的内容,将它们保存在ViewData属性中也不起作用,并且我也不想使用Session,因为此属性仅在此特定视图中有用.

In JSF I remember that you could use the @ViewScope annotation for this scenario, but is there something similar in ASP MVC? For what I've read saving them in the ViewData property will not work either and I do not want to use the Session because this properties will only be relevant in this particular view.

推荐答案

如果我正确理解了您的问题,那么您可能正在寻找TempData之类的东西.

If I understand your question correctly, you may be looking for something like TempData.

您可以在此处阅读有关内容: http://blogs.teamb.com/craigstuntz/2009/01/23/37947/

You can read about it here: http://blogs.teamb.com/craigstuntz/2009/01/23/37947/

可以在这里找到最新的帖子: http://codeoverload.wordpress.com/2011/05/29/controller-tempdata-in-asp-net-mvc-3/

A more recent post can be found here: http://codeoverload.wordpress.com/2011/05/29/controller-tempdata-in-asp-net-mvc-3/

这篇关于ASP MVC中是否有等效的JSF @ViewScope?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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