On my MVC project I have a 'Contact Us' form on the footer of the Layout page so the 'Contact Us' form appears on each page of the website.
I have to check each time the form is submitted, on which page was it, I mean the url of the page that submitted the 'Contact Us' form in its POST method.
For example on the homepage:
http://www.test.com/myWebSite.Site/Home
I need the get: Home
But the problem is that when I submit the form with a POST request, in the Action, Request.Url always gives me that: (The root of the Controller and the Action..)
http://www.test.com/myWebSite.Site/Shared/SubmitContactForm
I think that what I need is the URL of the step before... I am not sure how to do that, any idea?
string returnUrl) and add it in the form -@using(Html.BeginForm( new { returnUrl = Request.RawUrl })) { ... }(or if you did not want it as a query string, then you could assign it to a hidden input that binds to a view model property)