2015-10-16 60 views
0

我有一個寫在我的控制器中的方法。我將值作爲查詢字符串傳遞給此控制器。示例URL到控制器的方法是:無法獲取查詢字符串參數的值

了window.location =「http://www.myapplication.org/Session/Enter?legacySessionId=fjD0pMTFTPFf6MgJZT0&RedirectPath=/Folio/OfflineDocument/EnqueueDocumentGenerationRequest/?FolderId=acf7egfsc0clz6ei&CourseId=vhvgyhgvhgvyy7yty

我的控制器方法如下定義:

[AcceptVerbs(HttpVerbs.Get)] 
     public ActionResult Enter(
      string legacySessionId, 
      string RedirectPath, 
      string siteSubdomain = "", 
      bool isDuplicate = false, 
      int id = 0 
     ) 

這裏面控制器的方法時,我得到了RedirectPath查詢字符串值它只是給出了:

RedirectPath="/Folio/OfflineDocument/EnqueueDocumentGenerationRequest/?FolderId=acf7egfsc0clz6ei" 

鑑於預期的結果是:

RedirectPath="/Folio/OfflineDocument/EnqueueDocumentGenerationRequest/?FolderId=acf7egfsc0clz6ei&CourseId=vhvgyhgvhgvyy7yty" 

缺少「CourseId」部分。有人能指出這個問題嗎?

回答

1

你必須編碼符號字符:

& ==> & 

爲了將是:

window.location = "http://www.myapplication.org/Session/Enter?legacySessionId=fjD0pMTFTPFf6MgJZT0&RedirectPath=/Folio/OfflineDocument/EnqueueDocumentGenerationRequest/?FolderId=acf7egfsc0clz6ei&CourseId=vhvgyhgvhgvyy7yty"

&是在網址參數的分隔符。如果這個char是值的一部分,它必須被編碼。

1

您需要在參數中跳過&符號。只需編碼該參數值。

window.location = "http://localhost:13203/Home/Enter?legacySessionId=fjD0pMTFTPFf6MgJZT0&RedirectPath=" 
        + encodeURIComponent("/Folio/OfflineDocument/EnqueueDocumentGenerationRequest/?FolderId=acf7egfsc0clz6ei&CourseId=vhvgyhgvhgvyy7yty");