Q:

Sending text via ViewBag asp.net mvc

I have a string which I add in my controller..
ViewBag.mydata = "a,x,b,\na,y,b,....."

In my view in javascript code I call..
var myvar= @ViewBag.mydata;

when I see the view source html I find 
var myvar = a,x,b,
            a,y,b,
            .......

I need myvar to be the string I sent in ViewBag..
Thanks

A:

Try
var myvar= '@ViewBag.mydata';

Seems you having that because with @ViewBag.mydata you outputing just contents of your C# string to make it as a javascript string you need to wrap that into quotes.
Update 1.
If you wan't to keep your \n's displaying you need to escape \ and that could be achieved by duplicating that sign:
var myvar= '@ViewBag.mydata'.replace('\n', '\\n');

