I am creating a web app using asp.net and angularjs i am passing my session variable from c# to javascript as follows
<script type="text/javascript">
var pm = "<%= Convert.ToString(Session["mysession"]) %>";
var log = "<%= Convert.ToString(Session["radio"]) %>";
</script>
but i am getting error: BC30203: Identifier expected.
on: Line 111: var pm = "<%= Convert.ToString(Session["mysession"]) %>";
what could be the possible reason for this?
More than likely, the output of Session["mysession"]
contains a quote and is prematurely ending your expression, creating invalid syntax after the inner quote.
If you know there will be no single-quotes, switch to that (below), otherwise, escape the quote when setting Session["mysession"]
on the server side.
var pm = '<%= Convert.ToString(Session["mysession"]) %>';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.