Simple question about adding data to Javascript

advertisements

I am using an mvc application and in _Layout.cshtml page I have some javascript I wanna pass it a value of

 System.Configuration.ConfigurationManager.AppSettings["anID"].ToString()

here

<script type="text/javascript">
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount',PASS THAT HERE!]);

How do I do this? I am not sure how to pass data to javascript??


You could try like this:

<%
    var value = System.Configuration.ConfigurationManager.AppSettings["anID"].ToString();
%>
<script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', <%= value %>]);
</script>

or with the Razor view engine:

@{
    var value = System.Configuration.ConfigurationManager.AppSettings["anID"].ToString();
}
<script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', @value]);
</script>