我将一个预制的 URL 字符串作为模型传递给我在 MVC 项目中的 View 。
我将 URL 作为 encodingURIComponent 传递给我的 Controller :
window.location = '@Url.Content("~/Default/UserAgreement?registerData=")' + encodeURIComponent(jsonHttp);
然后我将字符串作为模型传递
public ActionResult UserAgreement(String registerData)
{
return View(null, null, System.Uri.UnescapeDataString(registerData));
}
然后当我尝试记录它时,我无法摆脱
&
这些都不起作用:var urlString = '@Model'.replace("&", "&");
console.log(urlString);
var urlString = decodeURIComponent('@Model');
console.log(urlString);
我究竟做错了什么??
最佳答案
您可能只需要更换 global
与 /g
正则表达式上的修饰符,否则它只会替换 &
的第一个实例:
var urlString = '@Model'.replace(/&/g, '&');
console.log(urlString);
片段示例:
var str = 'Something & Else && Here';
alert( str );
alert( str.replace(/&/g, '&') );
关于jquery - 删除放大器;来自javascript中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26038483/