user1640256
user1640256

Reputation: 1719

Unable to get values of querystring parameters

I have a method written in my controller. I am passing values to this controller as querystring. The sample url to that controller method is:

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

My controller method has following definition:

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

Inside this controller method when I get the querystring value for RedirectPath it only gives:

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

Whereas the expected result is :

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

It is missing "CourseId" part. Can someone point out the issue?

Upvotes: 0

Views: 165

Answers (2)

Shishir Kushwaha
Shishir Kushwaha

Reputation: 163

You need to escape ampersand in parameter. Just encode that parameter value.

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

Upvotes: 1

Steve B
Steve B

Reputation: 37660

You have to encode the ampersand char:

& ==> &

To will be:

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

& is the separator of arguments in the url. If this char is part of the value, it has to be encoded.

Upvotes: 1

Related Questions