我将预制 URL 字符串作为模型传递到 MVC 项目中的 View 。
我将 URL 作为编码的 URIComponent 传递给我的 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);
我做错了什么?
最佳答案
您可能只需要在正则表达式上使用 /g
修饰符替换 global
,否则它只会替换 &< 的第一个实例
:
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/