在MVC3中,我在将模型变量输出到JavaScript中时收到“关闭条件编译”警告
我正在使用ASP.NETMVC3和Razor。以下是导致警告的代码:在MVC3中,我在将模型变量输出到JavaScript中时收到“关闭条件编译”警告,javascript,visual-studio-2010,razor,compiler-warnings,Javascript,Visual Studio 2010,Razor,Compiler Warnings,我正在使用ASP.NETMVC3和Razor。以下是导致警告的代码: var userLocation = new google.maps.LatLng(@Model.Latitude, @Model.Longitude); 代码在运行时运行良好,但我想了解警告 编辑 以下是更多相关代码: function initialize() { directionsDisplay = new google.maps.DirectionsRenderer(); v
var userLocation = new google.maps.LatLng(@Model.Latitude, @Model.Longitude);
代码在运行时运行良好,但我想了解警告
编辑
以下是更多相关代码:
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var userLocation = new google.maps.LatLng(@Model.Latitude, @Model.Longitude);
var myOptions = {
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: userLocation
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
}
如果我这样添加括号:
var userLocation = new google.maps.LatLng(@(Model.Latitude), @(Model.Longitude));
我收到一个新的警告,无效字符。问题不在您提供的行中,它只是基于您提供的代码之外的错误导致警告
一般来说,这是一个js错误,与Razor或VS无关,但通常是由于缺少括号或s引号引起的。你能分享一下周围的代码吗?sry如果我不清楚,如果错误在这一行之外,那么这一行中没有括号缺失。您提供的扩展代码表明,在使用razor语法时,似乎会立即出现错误,这是一个明确的迹象,表明在html/js中存在错误之前,您可以提供完整的代码垃圾,包括脚本标记吗?