2011-11-03 80 views
0

在頁面上我有以下幾點:重定向我的網頁保存爲一個會話變量的網頁URL

@{ Session["CurrentUrl"] = Request.Url.ToString(); } 

我然後調用另一個頁面,在該頁面的操作方法,我試圖回到原來的使用頁面下面

return Session["CurrentUrl"] == null ? 
    Index() : 
    Redirect(Session["CurrentUrl"]); 

的方法似乎不錯,但,當我試圖實現這個我收到的錯誤說:

Error 51 The best overloaded method match for 'System.Web.Mvc.Controller.Redirect(string)' has some invalid arguments  
"Error 52 Argument 1: cannot convert from 'object' to 'string') 

任何人都可以幫助告訴我這裏有什麼問題。我不知道如何解決這個錯誤。

回答

1

你需要投Session["CurrentUrl"]string因爲該方法需要一個字符串

return Session["CurrentUrl"] == null ? 
    Index() : 
    Redirect((string)Session["CurrentUrl"]);