I have the following on a page:
@{ Session["CurrentUrl"] = Request.Url.ToString(); }
I then call another page and in the action method of that page I try to return to the original page using the following
return Session["CurrentUrl"] == null ?
Index() :
Redirect(Session["CurrentUrl"]);
The method seemed good but when I tried to implement this I received errors saying:
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')
Can anyone help by telling me what’s wrong here. I am not sure how I can fix this error.
You need to cast
Session["CurrentUrl"]tostringbecause the method expects a string