简体   繁体   English

ASP.NET MVC - 如何将帖子中的FormCollection数据传递给另一个Action?

[英]ASP.NET MVC - How can I pass FormCollection data in a post to another Action?

I have a page "Results" with a form and when "submit" is clicked, the form is submmited to another Action. 我有一个带有表单的“结果”页面,当单击“提交”时,表单将被设置为另一个操作。 So far, so good... 到现在为止还挺好...

But, this works fine just if user is logged in. If not, he will be redirected to "Login" page and my FormCollection loses its data. 但是,这只是在用户登录时工作正常。如果没有,他将被重定向到“登录”页面,我的FormCollection丢失了它的数据。

Is there a way to persist this data without using TempData?? 有没有办法在不使用TempData的情况下保留这些数据?

Thanks!! 谢谢!!

I don't think that's possible. 我不认为这是可能的。 The only thing the system remembers during the redirect to the login page is the 'return url'. 系统在重定向到登录页面期间唯一记住的是“返回网址”。 No post data is saved (this could be megabytes of data...) 没有保存帖子数据(这可能是数兆字节的数据...)

You can use the Session object as alternative, or make sure that the user is logged in before you post. 您可以使用Session对象作为替代,或者确保在发布之前用户已登录。

Or, if it's just a search result, try to live without the POST, and use a GET (which also has other advantages) 或者,如果它只是一个搜索结果,尝试在没有POST的情况下生存,并使用GET(这也有其他优点)

我宁愿不允许未经授权的用户访问“结果”页面或至少向他显示消息“请先登录”而不是表格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM