Boj*_*les 1 javascript asp.net-mvc
我在Webforms网站上的iFrame中有一个MVC表单.表单通过以下代码提交,但我希望它重定向到Webforms站点上的父页面.它不起作用,因为我不能让RedirectResult定位父.从我过去学到的是,它无法做到?
[HttpPost]
public ActionResult Index(string FindText, string FindTown)
{
return new RedirectResult("http://www.thesite.com/SearchResults.aspx?SearchText=" + SearchText + "&Town=" + Town);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法可以通过Javascript从Action内部定位父级来实现我想要的结果?
例如.使用,
window.parent.location.href
Run Code Online (Sandbox Code Playgroud)
如果这是可能的,我该如何写呢?
您可以尝试返回JavaScriptResult:
return new JavaScriptResult
{
Script = string.Format("window.parent.location.href = '{0}'", url)
};
Run Code Online (Sandbox Code Playgroud)
或ContentResult:
return ContentResult
{
Content = string.Format("<script type="text/javascript">window.parent.location.href = '{0}';</script>", url),
ContentType = "text/html"
};
Run Code Online (Sandbox Code Playgroud)