我试图在Razor里写JS代码,但是不行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<script type="text/javascript">
  
//some javascrpt code here to display map etc
  
  
//now add markers
 @foreach (var item in Model) {
  
      var markerlatLng = new google.maps.LatLng(@(Model.Latitude), @(Model.Longitude));
      var title = '@(Model.Title)';
      var description = '@(Model.Description)';
      var contentString = '<h3>' + title + '</h3>' + '<p>' + description + '</p>'
  
      var infowindow = new google.maps.InfoWindow({
          content: contentString
      });
  
      var marker = new google.maps.Marker({
          position: latLng,
          title: title,
          map: map,
          draggable: false
      });
  
      google.maps.event.addListener(marker, 'click', function () {
          infowindow.open(map, marker);
      });
  
  
      }
</script>

解决方法 1:

使用<text>这个伪元素来强制Razor从编译模式返回到内容模式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<script type="text/javascript">
  
//some javascrpt code here to display map etc
  
  
//now add markers
 @foreach (var item in Model) {
    <text>
      var markerlatLng = new google.maps.LatLng(@(Model.Latitude), @(Model.Longitude));
      var title = '@(Model.Title)';
      var description = '@(Model.Description)';
      var contentString = '<h3>' + title + '</h3>' + '<p>' + description + '</p>'
  
      var infowindow = new google.maps.InfoWindow({
          content: contentString
      });
  
      var marker = new google.maps.Marker({
          position: latLng,
          title: title,
          map: map,
          draggable: false
      });
  
      google.maps.event.addListener(marker, 'click', function () {
          infowindow.open(map, marker);
      });
  
   </text>
      }
</script>

最新文章

  1. 《寒江独钓_Windows内核安全编程》中修改类驱动分发函数
  2. mysql字符串处理例子
  3. 一步一步教你如何解锁被盗的iPhone 6S
  4. 替换Notes,K2 BPM为vivo打造新平台
  5. emoji表情引发的JNI崩溃
  6. LCA(RMQ)
  7. Hibernate逍遥游记-第3章对象-关系映射基础-access=&quot;field&quot;、dynamic-insert、dynamic-update、formula、update=false
  8. Android开发之sharedpreferences 详解
  9. sql语句各种九九乘法表
  10. [TYVJ] P1044 数字三角形
  11. ARM相关知识
  12. [OpenCV] Write &amp; Read files
  13. 随手科技(随手记)2017招聘Java工程师笔试题
  14. vue 高德地图使用 vue-amap
  15. Expo大作战(三十六)--expo sdk api之 ImagePicker,ImageManipulator,Camera
  16. CSS魔法(四)常用属性
  17. flask框架----数据库连接池
  18. Abp中SwaggerUI的接口文档添加上传文件参数类型
  19. P2426 删数
  20. servlet 3.0无需配置web.xml,使用注入方式配置servlet实现登陆功能(服务器需要支持servlet3.0)

热门文章

  1. Mongodb 的常用方法,在可视化工具执行
  2. 【WPF】使用CefSharp嵌入HTML网页
  3. C# 中的await
  4. C语言 &#183; 递归求二项式系数值
  5. PostgreSQL Table Partitioning&lt;转&gt;
  6. go语言简述
  7. Extjs js 产生Guid或者UUID
  8. android开发(29) 自定义曲线,可拖动,无限加载
  9. sql索引创建
  10. TiKV 源码解析系列 - Raft 的优化