我有一个在我的控制器中编写的方法。我将值作为查询字符串传递给此控制器。该控制器方法的示例网址是:
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"部分。有人可以指出这个问题吗?
答案 0 :(得分:1)
你必须编码&符号:
& ==> &
将成为:
window.location = "http://www.myapplication.org/Session/Enter?legacySessionId=fjD0pMTFTPFf6MgJZT0&RedirectPath=/Folio/OfflineDocument/EnqueueDocumentGenerationRequest/?FolderId=acf7egfsc0clz6ei&CourseId=vhvgyhgvhgvyy7yty"
&
是url中参数的分隔符。如果此char是值的一部分,则必须对其进行编码。
答案 1 :(得分:1)
你需要在参数中转义&符号。只需编码该参数值。
window.location = "http://localhost:13203/Home/Enter?legacySessionId=fjD0pMTFTPFf6MgJZT0&RedirectPath="
+ encodeURIComponent("/Folio/OfflineDocument/EnqueueDocumentGenerationRequest/?FolderId=acf7egfsc0clz6ei&CourseId=vhvgyhgvhgvyy7yty");