I pass a premade URL string as a model to my view in a MVC-project.
I pass the URL as an encodedURIComponent to my controller:
window.location = '@Url.Content("~/Default/UserAgreement?registerData=")' + encodeURIComponent(jsonHttp);
Then i pass the string as a model
public ActionResult UserAgreement(String registerData)
{
return View(null, null, System.Uri.UnescapeDataString(registerData));
}
Then when i try to log it i can't get rid of the & None of these work:
var urlString = '@Model'.replace("&", "&");
console.log(urlString);
var urlString = decodeURIComponent('@Model');
console.log(urlString);
What am i doing wrong??
You probably just need to make your replace global with the /g modifier on a regex, otherwise it will only replace the first instance of &:
var urlString = '@Model'.replace(/&/g, '&');
console.log(urlString);
Snippet example:
var str = 'Something & Else && Here';
alert( str );
alert( str.replace(/&/g, '&') );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With