views:

1263

answers:

2

I have an action method that depending on some conditions needs to return a partial view via ajax, or redirect to another Controller/Action. The correct view is returned but it is placing it in the Ajax forms UpdateTargetId rather than redirecting to a completely new page. Anyone have any idea how I can accomplish this?

A: 

May be this link could help to solve your problem, and insert your javascript to change current page to other controller, for example

window.location = 'controller/action';
pocheptsov
+1  A: 

I think I would refactor this to use jQuery rather than MVC Ajax. jQuery will give you a lot more control over what you can do with the result that you get back. If that's not an option, you might want to look at the OnComplete callback and see what data you get passed to it and see if there is a way get the url that you want to be redirected to from it.

Also, I seem to remember that if you return a JavaScriptResult it will execute it regardless of how the AJAX was invoked. You might want to try something like:

return JavaScript( "window.top.location.href ='" + Url.Action( "Action" ) + "';" );
tvanfosson
Worked wonderfully thanks for your help.