在asp.net mvc中提交表单后重定向到上一个操作

时间:2022-12-31 16:39:17

I have a form on all my pages that allows the user to select their language. After this action completes I change the current language for that user then I need to make sure I redirect to the same action they were on previously.

我的所有页面上都有一个表单,允许用户选择他们的语言。完成此操作后,我更改了该用户的当前语言,然后我需要确保我重定向到之前的相同操作。

I am not sure what the best approach is to do this in asp.net mvc. One approach is that on every page I save the controller and action as hidden variables in the language form.

我不确定在asp.net mvc中执行此操作的最佳方法是什么。一种方法是在每个页面上我将控制器和操作保存为语言形式的隐藏变量。

The other would to save the last controller and action into tempdata and then referencing it in the action that sets the current language.

另一个是将最后一个控制器和操作保存到tempdata中,然后在设置当前语言的操作中引用它。

Any thoughts on which approach or another that is best for this scenario?

有关哪种方法或其他方法最适合此方案的任何想法?

2 个解决方案

#1


1  

The request URL of the page the forms lives on has all the necessary information about the Controller and the Action. So, if you add it as a returnurl (or simply ru) parameter to the form, you can redirect from the POST action to that URL instead of trying to find the right Controller and Action.

表单所在页面的请求URL包含有关Controller和Action的所有必要信息。因此,如果将其作为returnurl(或简称ru)参数添加到表单中,则可以从POST操作重定向到该URL,而不是尝试查找正确的Controller和Action。

#2


0  

You can also refer the demo available at http://karticles.blogspot.com/2009/12/aspnet-mvc-pattern-var-controllersview.html

您也可以参考http://karticles.blogspot.com/2009/12/aspnet-mvc-pattern-var-controllersview.html上提供的演示。

#1


1  

The request URL of the page the forms lives on has all the necessary information about the Controller and the Action. So, if you add it as a returnurl (or simply ru) parameter to the form, you can redirect from the POST action to that URL instead of trying to find the right Controller and Action.

表单所在页面的请求URL包含有关Controller和Action的所有必要信息。因此,如果将其作为returnurl(或简称ru)参数添加到表单中,则可以从POST操作重定向到该URL,而不是尝试查找正确的Controller和Action。

#2


0  

You can also refer the demo available at http://karticles.blogspot.com/2009/12/aspnet-mvc-pattern-var-controllersview.html

您也可以参考http://karticles.blogspot.com/2009/12/aspnet-mvc-pattern-var-controllersview.html上提供的演示。