我正在做书呆子晚餐。我想使用 Razor 语法而不是 Web 表单。当我调试项目时。它说“模型”没有定义。整个显示的错误如下:
Unhandled exception at line 133, column 9 in http://localhost:52372/Dinner/Create
0x800a1391 - Microsoft JScript runtime error: 'Model' is undefined
它生成了一个名为
Create[dynamic]
文件是什么意思,我的 Razor 语法有什么问题。
提前致谢。
原始语法
<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2" type="text/javascript"></script>
<script src="/Scripts/Map.js" type="text/javascript"></script>
<div id="theMap">
</div>
<script type="text/javascript">
$(document).ready(function() {
var latitude = <%=Model.Latitude%>;
var longitude = <%=Model.Longitude%>;
if ((latitude == 0) || (longitude == 0))
LoadMap();
else
LoadMap(latitude, longitude, mapLoaded);
});
function mapLoaded() {
var title = "<%=Html.Encode(Model.Title) %>";
var address = "<%=Html.Encode(Model.Address) %>";
LoadPin(center, title, address);
map.SetZoomLevel(14);
}
</script>
剃刀语法
@model NerdDinner.Models.Dinner
<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2" type="text/javascript"></script>
<script src="/Scripts/Map.js" type="text/javascript"></script>
<div id="theMap">
</div>
<script type="text/javascript">
$(document).ready(function () {
var latitude = Model.Latitude;
var longitude =Model.Longitude;
if ((latitude == 0) || (longitude == 0))
LoadMap();
else
LoadMap(latitude, longitude, mapLoad);
});
function mapLoad()
{
var title = "@Html.Encode(Model.Title)"
var address = "@Html.Encode(Model.Address)"
LoadPin(center,title,address);
map.setZoomLevel(14);
}
</script>