Home > Back-end >  Query String parameter value truncate after #
Query String parameter value truncate after #

Time:10-27

Problem - The query string parameter value is getting truncated if I have # in the parameter string value.

I have a table where I am binding the anchor tag <a/> prop href value like below;

<a href="/FileDetails/[email protected]&[email protected]">

after binding on browser:

<a href="/FileDetails/DownloadBlob?dirName=RSHSYNCADE&amp;blobName=J231132 anyfoostringnjectable barfoorBstringch #212422627, string Batch #145876V.pdf">

In the above anchor tag for href prop value I am setting a Controller/Action along with the query string parameters dirName and blobName.

But when the control comes to the specified action method of the controller it truncates the second param value from # means I can only see a value upto J231132 anyfoostringnjectable barfoorBstringch.

While trying to find a fix on internet, I am unable to find a proper solution which fit to my scenario till now.

Can anyone please help me to understand what causing this issue and what would be the fix for these kind of issues?

CodePudding user response:

You need to encode the url that you put in the anchor href. If that values comes from the server, use HttpServerUtility.UrlEncode when you set the href tag. Otherwise you can use encodeURIComponent function in javscript or replace the "#" with "#"

CodePudding user response:

Query string URL must be encoded, there is some special characters for instance if you put plus( ) in query string. It will be handle as space because handler will detect it as an encoded string then will replace it with space.

Encoded form of plus( ) is + Encoded form of sharp(#) is #

if you send the sharp value as # will handle as a sharp(#) and you won't have problem.

As helper you may use URi builders. There is many NuGet package exist.

  • Related