0

I have a very simple problem - I try to assign a server variable into a javascript variable;

e.g.

 var data = @(DateTime.Now.Day.ToString() + " " + System.Globalization.CultureInfo.GetCultureInfo("pl-PL").DateTimeFormat.GetMonthName(DateTime.Now.Month) + ", " + DateTime.Now.Year.ToString());

 alert(data);

the alert doesn't show, where's the bug ?

The source output is

var data = 4 , ;

alert(data);

but should be 4 december 2011

1
  • 1
    did you view source the output? what do you see when you do? Commented Dec 4, 2011 at 19:15

1 Answer 1

2

You need to wrap it in quotes

var data = "@(DateTime.Now.Day.ToString() + " " + System.Globalization.CultureInfo.GetCultureInfo("pl-PL").DateTimeFormat.GetMonthName(DateTime.Now.Month) + ", " + DateTime.Now.Year.ToString())";
alert(data);

Then I get the following alert:

"5 grudzień, 2011"

If you think about it - without quotes wrapped around the string, it is not valid javascript.

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.