在view(cshtml)中的JavaScript中使用Razor语法是否可行或有解决方法?
我正在尝试将标记添加到Google地图中...例如,我试过这个,但是我收到了大量的编译错误:
<script type="text/javascript">
// Some JavaScript 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 () { …Run Code Online (Sandbox Code Playgroud) 如何从@Modeljquery脚本中获取值.我希望从我的模型中获取索引(由我的自定义表中的行选择确定)获取一些属性IEnumerable<T>.我不想在表中显示此属性并执行类似单元格的操作.val()
例如 :
var selectedRow = $(this).parent().children().index($(this)) - 1;
Run Code Online (Sandbox Code Playgroud)
我想要类似的东西
@Model.ElementAt(selectedRow).SomeProperty
Run Code Online (Sandbox Code Playgroud)
内部脚本
谢谢