Vassilis
Vassilis

Reputation: 828

Adding a url.action to a anchor tag using javascript not working

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.

Upvotes: 0

Views: 428

Answers (1)

Siva Rm K
Siva Rm K

Reputation: 294

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>';

Upvotes: 1

Related Questions