@symbol in JavaScript block

I have a JavaScript function like this in my ASP.NET MVC 3 application.

function Foo()
{
   var url = "@Url.Action("MyAction", "MyController")";
   alert(url);
}

I am confused why the above code works . I expected to escape @Url.Action(...)inside the tags <%=?

+5
source share
3 answers

This is a feature of the Razor viewer β€” it controls the switch between HTML / Javascript and the server side viewer code, so you don't need to avoid it in most cases.

See Scott Guthrie's blog post: http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx

+4
source

, Razor.

: , JavaScript (cshtml)

+2

Yes, it works on razor view pages, but intellisense does not work inside the "or" view mechanism as a web form.

0
source

All Articles