Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
when i define in javascript
var whoami = @ViewBag.myname
it is not work or render they render
var whoami = ;
i am trying it @(ViewBag.myname) // not worked too.
are their any way to do this in raor MVC 3
Is @ViewBag.myname empty?
@ViewBag.myname
Enclose the variable in quotes, so to have a correct javascript string:
var whoami = "@ViewBag.myname";
also ensure that myname doesn't contain quotes too (or escape them).
myname
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.