I really believe that you need to be using the Request object, instead of getting the QueryString property, because in the code above this one, you're using the same method I'm talking about. The value is null, only because there is
- either no QueryString with this name
- or the value of it is null
- or the data was sent as a POST request, not as GET; same as option 1.
Html.BeginForm("Login", "Login", FormMethod.Post,
new { ReturnUrl = Request["ReturnUrl"]});
.. this would get the ReturnUrl from the Request, whether it is attached as a QueryString, or passed through a Form. QueryString method would only return a string as a value, if there is a QueryString for ReturnUrl appended to the URL (such as this one page?ReturnUrl=defaultPage). Whereas, the Request method will capture the data even if it was passed from the form, or if it is attached to the URL; in both cases.
I would myself, go with the simple Request method of getting the data, because it a chance of data being passed from a form with a POST method, in this case there is no QueryString and not only this, but many other conditions also show up where
.QueryString
method fails.