Razor variable into Javascript

后端 未结 1 590
暗喜
暗喜 2020-12-19 18:51

I am trying to set a JavaScript variable from a model variable using Razor, and can\'t figure out what is wrong. In the CSHTML page, I\'ve tried the following ways:

相关标签:
1条回答
  • 2020-12-19 19:25

    If you need to set a variable to a string literal, then it needs to be enclosed in quotes. For example:

    <script>
       var test1 = '@Model.testVariable';
    </script>
    
    0 讨论(0)
提交回复
热议问题