1

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

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

1 Comment

i am not try it but i solve the problem by another way not using this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.