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