0

我试图将模型的属性值插入到 javascript 变量中,但它不起作用。

我尝试了以下方法:

 <script type="text/javascript">
    var sample = "@(Model.MyProperty)";
 </script>

 <script type="text/javascript">
    var sample = "@Model.MyProperty";
 </script>

 <script type="text/javascript">
    var sample = @Model.MyProperty;
 </script>

 <script type="text/javascript">
 @{
    var sample = Model.MyProperty;
  }
 </script>
4

1 回答 1

2

这个应该工作

<script type="text/javascript">
    var sample = "@Model.MyProperty";
</script>

你得到什么错误?

于 2012-04-20T10:19:11.630 回答