I am trying to add a url.action method to an anchor tag dynamically but for some reason it keeps adding a space between the url.action part and my action name.
here is the javascript code:
var contentString = '<h3 class="info-window-title">Name of NPO</h3>' + '<a href="@Url.Action("Wallet","Wallet")">Click me to donate!</a>';
here is the code once i inspect the anchor tag using chrome dev tools:
<a href="@Url.Action(" wallet","wallet")">Click me to donate!</a>
It keeps adding a space before wallet and i have no idea why. any help would be much appreciated.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I could see some problem in string concatenation, you have to use backslash character for double quote /single quote inside string literal
var contentString = '<h3 class="info-window-title">Name of NPO</h3>' +
'<a href="@Url.Action('Wallet','Wallet')">Click me to donate!</a>';
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0