I am trying to combine some javascript with server-side variable.
Here I'm trying to replace the "<" sign with the actual less than sign:
@{
string age = '<1'; // assume I got it from the QueryString
<text>$('#select1').val('@age'.replace('<','<'));</text> // and when the parser sees the '<' symbol it thinks I'm trying to close the <text> tage
}
Is there any way that symbol can be escaped/ignored?
I ended up using @(Html.Raw("<"))
Try this:
Note, it does have to be between script tags for it to work.. (I'm assuming this is the case though)
<script>
@{
string age = '<1'; // assume I got it from the QueryString
@: $('#select1').val('@age'.replace('<','<')); // and when the parser sees the '<' symbol it thinks I'm trying to close the <text> tage
}
</script>
Update
Incidently, the text syntax you used above will also work (instead of @:).. specifically what is causing the problem in your example is not the < in the javascript, rather the second
<text>
in the comment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With