1

I have a MVC form in an iFrame on a Webforms site. The form submits via the following code but I would like it to redirect to the parent page on the Webforms site. It doesn’t work as I can’t get RedirectResult to target the parent. From what I have learnt in the past is that it can’t be done?

[HttpPost]
public ActionResult Index(string FindText, string FindTown)
{
    return new RedirectResult("http://www.thesite.com/SearchResults.aspx?SearchText=" + SearchText + "&Town=" + Town);
}

Is there a way I can target the parent via Javascript from inside the Action to achieve the result I would like?

e.g.. using,

window.parent.location.href

if this is possible how would I write it?

0

1 Answer 1

6

You can try return JavaScriptResult:

return new JavaScriptResult 
{
    Script = string.Format("window.parent.location.href = '{0}'", url)
};

or ContentResult:

return ContentResult
{
    Content = string.Format("<script type="text/javascript">window.parent.location.href = '{0}';</script>", url),
    ContentType = "text/html"
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.