1

In my jQuery function I have this line to create an MVC URL:

$('#response').append("<a href=\'\@Url.Action(\"Details\",\"Member\")\'>my link</a>")

My understanding is that I need to escape the @ character in order to get the link working, but it won't let me. Is there another way to render the link I'm trying to create?

1
  • This will not work because Url.Action is C# code. Try $('#response').append('<a href="/Details/Member">my link</a>'); Commented Dec 14, 2016 at 11:21

1 Answer 1

1

The result of the Razor code is output on the server, long before the JS runs, so you don't need to escape anything. This should work for you, so long as the value @Url.Action provides is valid and you execute this where the Razor syntax will be interpreted (ie. not in an external .js file):

$('#response').append('<a href="@Url.Action("Details","Member")">my link</a>');
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.