Unable to redirect to another action or url in controller

Lea Lebonski asked on February 13, 2020 01:55

Hi All,

We run Kentico 12 MVC. I have got a widget with a simple form fed from a soap web service via Ajax. I am pushing the form data back to controller in a post action via model and am forming an external url to which I want to redirect.

However when using ActionResult with Redirect() or RedirectToAction() - as a trial of different redirect, I get and Internal server error and a message of: Child actions are not allowed to perform redirect actions.

I have searched the internet for answer but am no wiser to how to apply this to solve the problem in Kentico. Has anybody encountered this issue before?

Thanks,

L.

Correct Answer

Dat Nguyen answered on February 13, 2020 07:26

Since you're doing a POST via Ajax, it's probably not allowed to do a server-side redirect in that controller method. Instead you would return the redirect Url to the client and have the client redirect by setting window.location to the url.

Or try returning a JavascriptResult from your controller to achieve this.

To redirect:

return JavaScript("window.location = '@redirectUrl'");

2 votesVote for this answer Unmark Correct answer

Recent Answers


Lea Lebonski answered on February 14, 2020 09:35

Thank you for that. That proved to be a really good way of doing it. :-)

L.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.