2010-11-08 78 views
0

我正在使用Ajax.BeginForm來提交數據等,但是當我查看Request.Url等時,我得到了Ajax請求的URL。有沒有一種方法可以獲取用戶所在實際頁面的URL?mvc - 當前URL?不請求URL

基本上,我需要從URL中獲取id(routevalue),而不傳遞任何內容到Ajax-actionlink。

回答

1

爲什麼不直接通過你的請求需要的信息:你可以嘗試使用HttpRequest類的UrlReferrer財產

<%: 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" } 
) %> 
+0

因爲如果有更新包含剛剛發佈的ActionLink的div的Ajax請求,RouteData.Values會搞砸。 – TPR 2010-11-09 09:38:24

0

。我不確定它是否適用於您的應用程序的每個案例,但您可以嘗試一下。

+0

它不起作用。如果沒有任何Ajax調用,URLreferrer會指向不正確的東西 – TPR 2010-11-09 22:16:12