简体   繁体   中英

How to mix javascript with razor code

What the syntax to add the following javascript within my razor (chtml) template?

<script type="text/javascript">

 $(function(){ 
    @if(Model.IsModalShown)
    {
        $('#myModal').modal('show');
    }
 });

</script>
<script type="text/javascript">

$(function(){ 
    @if(Model.IsModalShown)
    {
        <text>$('#myModal').modal('show');</text>
    }
});

</script>

OR

<script type="text/javascript">

$(function(){ 
    if('@Model.IsModalShown' == 'True')
    {
        $('#myModal').modal('show');
    }
});

</script>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM