Is it possible or is there a workaround to use Razor syntax within JavaScript that is in a view (cshtml
)?
I am trying to add markers to a Google map...
A simple and a good straight-forward example:
This creates a script in your page at the location you place the code above which looks like the following:
Now you have a global JavaScript variable named razorUserName
which you can access and use on the client. The Razor engine has obviously extracted the value from @User.Identity.Name
(server-side variable) and put it in the code it writes to your script tag.