How can I avoid the next logic ? I have the next code in view:
<script type="text/javascript">
var x = $("#myId1").val();
@if(Model.IsOptions)
{
$('#myId2').click(function () { doSomething(); });
}
</script>
So, I want execute $(‘#myId2’).. only if ‘Model.IsOption’ is true. Currently Visual Studio underline it as wrong code.
The code inside @if should be C#, not JavaScript. Razor tries to execute it on server, not on client. To force it to treat it as JavaScript, you should use
<text></text>or@:, like this.