开发者

Asp.Net MVC Finding the previous page

开发者 https://www.devze.com 2023-01-27 01:42 出处:网络
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

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 ?


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

This method is not 100% reliable however.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消