相关疑难解决方法(0)

在JavaScript中使用Razor

在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)

javascript asp.net-mvc razor

419
推荐指数
10
解决办法
35万
查看次数

从jquery脚本中的@Model获取值

如何从@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)

内部脚本

谢谢

jquery model asp.net-mvc-3

11
推荐指数
1
解决办法
5万
查看次数

标签 统计

asp.net-mvc ×1

asp.net-mvc-3 ×1

javascript ×1

jquery ×1

model ×1

razor ×1