How to mix javascript with razor code

2019-09-08 15:10发布

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>

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-08 15:40
<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>
查看更多
登录 后发表回答