Possible Duplicate:
Mix Razor and Javascript code
Here is the code I’m trying to run:
// Razor code!
@if (User.Identity.IsAuthenticated) {
// This is Javascript, NOT C#/Razor code. Hence the '@' symbol.
var currentUser = @User.Identity.Name;
} else {
// Also Javascript code!
var currentUser = null;
}
Basically, I want to output this as Javascript if the user is logged in:
var currentUser = @User.Identity.Name;
Or this if the user is logged out:
var currentUser = null;
Well first you will want to change it to something like (remember your quotes around the
@User.Identity.Name):Then add some javascript: