Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use inline ASP.NET tags inside JavaScript?

How can I use ASP.NET inline tags from within a block of JavaScript? For example:

<script type="text/javascript">
     // Do some AJAX here, then redirect to a new page on the next line.
     window.location = "/Movie/" + <%= html.encode(MovieName) %>;
</script>
like image 599
royco Avatar asked Jan 23 '23 08:01

royco


1 Answers

Just like you have on the ASP.Net part, but you want it inside the quotes, like this:

window.location = "/Movie/<%= html.encode(MovieName) %>";

Since it echos out to the page, it will render like this:

window.location = "/Movie/MyMovie";

Outside the quotes it would look like this:

window.location = "/Movie/" + MyMovie;
//thinks MyMovie is a variable, not true!
like image 176
Nick Craver Avatar answered Jan 31 '23 16:01

Nick Craver