简体   繁体   English

返回重定向或转发

[英]Return a redirect or forward

I have done some research about this Stop initial action 我已经对此停止进行了一些初步研究

But it doesn't satisfy me. 但这让我不满意。 I have tried: 我努力了:

 forward(controller:"subtask", action:"create")
        return true

Result : 结果:

It returns the url but it's still on "subtask/create" page. 它返回URL,但仍在“子任务/创建”页面上。 My question is how should I stop the redirect which I just want to "redirect" my params to "subtask/create" but not redirect to that page . 我的问题是我应该如何停止仅将参数“重定向”到“ subtask / create”但不重定向到该页面的重定向

I think you need to think about your approach in a different way. 我认为您需要以不同的方式来考虑您的方法。

You want to send the parameters to the subtask create action ? 您想将参数发送给子任务创建动作吗? or you just want to call it but you don't want your page to redirect and yet you are using a method to redirect. 或者您只想调用它,但不希望页面重定向,但是您正在使用一种重定向方法。

It sounds like you are using a fork where you need a spoon. 听起来好像您在需要汤匙的地方使用叉子。

Approach 1. 方法1。

If you are attempting to call the method and pass the parameters. 如果您尝试调用该方法并传递参数。 If they are on the same controller then make the create method call a private method in the controller that takes generic params. 如果它们在同一控制器上,则使采用通用参数的控制器中的create方法调用私有方法。 On the same controller rather than forward just call the same private method from this action. 在同一个控制器上,而不是向前,只需从此操作中调用相同的私有方法即可。 ?

approach 2: If it is different controllers let the other controller carry out tasks via a service and call same service method here rather than redirect. 方法2:如果控制器不同,则让另一个控制器通过服务执行任务并在此处调用相同的服务方法,而不是重定向。

approach 3. Using ajax either post to other url pre posting or after returning to your next action and do nothing with result. 方法3.使用ajax将其发布到其他url之前,或者返回到您的下一个操作之后,对结果不执行任何操作。

You are currently forwarding/redirecting and saying you don't want to redirect well the answer is not to call redirect/forward if you don't wish to redirect/forward. 您当前正在转发/重定向,并说您不想很好地重定向,如果您不希望重定向/转发,答案是不调用重定向/转发。

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

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