我试图将模型的属性值插入到 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>