Novice
Novice

Reputation: 2487

Asp.Net MVC Finding the previous page

I have GenericPagecontroller in my project which renders GenericPage.aspx. There are links in the homepage and in two other pages for this GenericPageconroller.Now based on from where it is invoked, i have diiferent data to pass in to the GenericPage.aspx. ie If the Controller is requested from HomePage i have different set of data to show in the view and if it from other page i need to display diiferent set of data in the view. As of now i have kept an optional parameter in the Index method (the default method in GenericController) and added a querystring in the URL which holds the current page's name. Thus from the paramter i find from which link the request comes and load the appropriate data into the view.

Is there any way to achieve this instead having a querystring which carries the related information...? some way to dynamically to find this ?

Upvotes: 1

Views: 3721

Answers (2)

Shalin
Shalin

Reputation: 157

May be you can use TempData for storing the url before redirecting, however System.Web.HttpContext.Current.Request.UrlReferrer should help you

Upvotes: 1

Paul Creasey
Paul Creasey

Reputation: 28824

you can check Request.UrlReferrer which contains the referring page.

This method is not 100% reliable however.

Upvotes: 2

Related Questions