2012-05-05 25 views
1

我在WebForm站點上的iFrame中有一個MVC窗體。表單通過以下代碼提交,但我希望它重定向到Webforms網站上的父頁面。它不起作用,因爲我無法獲得RedirectResult來定位父級。從我以前學到的東西是不能做到的?通過iFrame從MVC重定向到父節點使用javascript的動作

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

有沒有一種方法可以通過Action內部的Javascript來實現我想要的結果?

e.g ..使用,

window.parent.location.href 

,如果這是可能的話我會怎麼寫呢?

回答

5

你可以嘗試返回JavaScriptResult:

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

或ContentResult類型:

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