adam78
adam78

Reputation: 10068

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>

Upvotes: 0

Views: 310

Answers (1)

AliRıza Adıyahşi
AliRıza Adıyahşi

Reputation: 15866

<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>

Upvotes: 3

Related Questions