TPR
TPR

Reputation: 2577

mvc - current URL? not request URL

I am using Ajax.BeginForm to submit data etc, but when I look at Request.Url etc I get the URL of the Ajax request. Is there a way I can get URL of the actual page the user is on?

Basically, I need to obtain id (routevalue) from the URL without passing anything to the Ajax-actionlink.

Upvotes: 0

Views: 882

Answers (2)

goenning
goenning

Reputation: 6654

You could try using the UrlReferrer property of the HttpRequest class. I'm not sure if it will work on every case of your application, but you could give it a try.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

Why not directly pass the information you need in the request:

<%: Ajax.ActionLink(
   "Some link text", 
   "ActionName", 
   // Notice how the id value is extracted from the route
   // and used to construct the link
   new { id = RouteData.Values["id"] },
   new AjaxOptions { OnSuccess = "success" }
) %>

Upvotes: 1

Related Questions