使用javascript从MVC操作通过iFrame重定向到父级

使用javascript从MVC操作通过iFrame重定向到父级,javascript,asp.net-mvc,Javascript,Asp.net Mvc,我在Webforms网站的iFrame中有一个MVC表单。表单通过以下代码提交,但我希望它重定向到Webforms站点上的父页面。它不起作用,因为我无法获得重定向结果以锁定父对象。从我过去学到的是,这是不可能做到的 [HttpPost] public ActionResult Index(string FindText, string FindTown) { return new RedirectResult("http://www.thesite.com/SearchResults.a

我在Webforms网站的iFrame中有一个MVC表单。表单通过以下代码提交,但我希望它重定向到Webforms站点上的父页面。它不起作用,因为我无法获得重定向结果以锁定父对象。从我过去学到的是,这是不可能做到的

[HttpPost]
public ActionResult Index(string FindText, string FindTown)
{
    return new RedirectResult("http://www.thesite.com/SearchResults.aspx?SearchText=" + SearchText + "&Town=" + Town);
}
是否有一种方法可以通过Javascript从操作内部将父对象作为目标,以实现我想要的结果

e、 g.使用

window.parent.location.href

如果可能,我将如何编写它?

您可以尝试返回JavaScriptResult:

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

return ContentResult
{
    Content = string.Format("<script type="text/javascript">window.parent.location.href = '{0}';</script>", url),
    ContentType = "text/html"
};

您可以尝试返回JavaScriptResult:

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

return ContentResult
{
    Content = string.Format("<script type="text/javascript">window.parent.location.href = '{0}';</script>", url),
    ContentType = "text/html"
};