Sometimes there may be such a requirement, I use it in the background:
HttpUtility.UrlEncode(str, System.Text.Encoding.UTF8);
Encode the Url. The front-end JS needs to use this content. At this time, it needs to be decoded:
Code
/**
* Url encoding
**/
ShengUtils.encode = function(unzipStr){
var zipstr="";
var strSpecial="!"#$%&'()* ,/:;<=>?[]^ `{|}~%";
var tt= "";
for(var i=0;ivar chr = unzipStr.charAt(i);
var c=ShengUtils.StringToAscii(chr);
tt = chr ":" c "n";
if(parseInt("0x" c) > 0x7f){
zipstr =encodeURI( unzipStr.substr(i,1));
}else{
if(chr==" ")
zipstr =" ";
else if(strSpecial.indexOf(chr)!=- 1)
zipstr ="%" c.toString(16);
else
zipstr =chr;
}
}
return zipstr;
}
/**
* Url decoding
**/
ShengUtils.decode=function(zipStr){
var uzipStr="";
for(var i=0;ivar chr = zipStr.charAt(i);
if(chr == " "){
uzipStr =" ";
}else if(chr=="%"){
var asc = zipStr.substring(i 1,i 3);
if(parseInt("0x" asc)>0x7f){
uzipStr =decodeURI("%" asc.toString() zipStr.substring (i 3,i 9).toString()); ;
i =8;
}else{
uzipStr =ShengUtils.AsciiToString(parseInt("0x" asc));
i = 2;
}
}else{
uzipStr = chr;
}
}
return uzipStr;
}
ShengUtils.StringToAscii=function(str ){
return str.charCodeAt(0).toString(16);
}
ShengUtils.AsciiToString = function(asccode){
return String.fromCharCode(asccode);
}