zoukankan      html  css  js  c++  java
  • Asp.net mvc怎么在razor里写js代码

    我试图在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
    <scripttype="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 (varitem inModel) {
        <text>
          varmarkerlatLng = newgoogle.maps.LatLng(@(Model.Latitude), @(Model.Longitude));
          vartitle = '@(Model.Title)';
          vardescription = '@(Model.Description)';
          varcontentString = '<h3>'+ title + '</h3>''<p>'+ description + '</p>'
      
          varinfowindow = newgoogle.maps.InfoWindow({
              content: contentString
          });
      
          varmarker = newgoogle.maps.Marker({
              position: latLng,
              title: title,
              map: map,
              draggable:false
          });
      
          google.maps.event.addListener(marker,'click',function() {
              infowindow.open(map, marker);
          });
      
       </text>
          }
    </script>
  • 相关阅读:
    海康API——获取监控点预览取流URL,获取的rtsp流不能播放
    MySQL——ON DUPLICATE KEY UPDATE添加索引值实现重复插入变更update
    maven——pom.xml的Missing artifact net.sf.json-lib:json-lib:jar:2.4 报错问题(两种有效的解决方案)
    Mysql——navicat如何导出mysql数据表结构
    MySQL——导入导出.sql文件
    仅用U盘就可以去除XP管理员密码
    测试

    navicat 或者workbench 无法连接127.0.0.1(61)的解决方法
    在linux中添加ftp用户,并设置相应的权限
  • 原文地址:https://www.cnblogs.com/sjqq/p/9031523.html
Copyright © 2011-2022 走看看