how to define dynamic variable in javascript
when i define in javascript
var whoami = @ViewBag.myname
it is not wo开发者_如何学Pythonrk 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?
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).
精彩评论