我正在将c#和ASP.NET MVC4用于Web应用程序(使用移动模板)。
我的详细信息视图页面出现问题。 (首先从索引页面选择一些内容,然后转到详细信息页面)我在页面上放置了一个bing地图,并且没有加载地图。
首先我认为地图有问题,但不是。
我注意到网址是
http://localhost:2550/Place/Details
的页面。但是,如果我手动将“1”放在最后,那么http://localhost:2550/Place/Details/1
然后地图加载到页面上。我不明白为什么会这样......
有谁知道为什么?感谢
我的详细信息页面视图:
@model Project.Models.Place
@{ ViewBag.Title = "Details";}
<h2>Place Details</h2>
<fieldset>
<div class="display-label"> Name: @Model.Name</div>
<div class="display-label">Address: @Model.Address</div>
<div class="display-label">Post Code: @Model.PostCode</div>
<div class="display-label"> PhoneNo: @Model.PhoneNo</div>
</fieldset>
<p> @Html.ActionLink("Back to List", "Index")</p>
<body onload="getMap();">
<div id='myMap' style="position:relative; width:400px; height:400px;"></div>
<div>
<input type="button" value="createWalkingRoute" onclick="createDirections();" />
</div>
<div id='directionsItinerary'> </div>
</body>
@section scripts{
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
var directionsManager;
var directionsErrorEventObj;
var directionsUpdatedEventObj;
function getMap() {
map = new Microsoft.Maps.Map(document.getElementById('myMap'), { credentials: 'mykey' });
}
function createDirectionsManager() {
var displayMessage;
if (!directionsManager) {
directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
displayMessage = 'Directions Module loaded\n';
displayMessage += 'Directions Manager loaded';
}
alert(displayMessage);
directionsManager.resetDirections();
directionsErrorEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', function (arg) { alert(arg.message) });
directionsUpdatedEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', function () { alert('Directions updated') });
}
function createWalkingRoute() {
if (!directionsManager) { createDirectionsManager(); }
directionsManager.resetDirections();
// Set Route Mode to walking
directionsManager.setRequestOptions({ routeMode: Microsoft.Maps.Directions.RouteMode.walking });
var seattleWaypoint = new Microsoft.Maps.Directions.Waypoint({ address: 'Seattle, WA' });
directionsManager.addWaypoint(seattleWaypoint);
var redmondWaypoint = new Microsoft.Maps.Directions.Waypoint({ address: 'Redmond, WA', location: new Microsoft.Maps.Location(47.678561, -122.130993) });
directionsManager.addWaypoint(redmondWaypoint);
// Set the element in which the itinerary will be rendered
directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsItinerary') });
alert('Calculating directions...');
directionsManager.calculateDirections();
}
function createDirections() {
if (!directionsManager) {
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', { callback: createWalkingRoute });
}
else {
createWalkingRoute();
}
}
</script>
}
我的控制器操作细节:
public ViewResult Details(int id)
{
ViewBag.events = eventRepository.PlaceEvents(id);
return View(placeRepository.Find(id));
}
答案 0 :(得分:1)
可能的原因,可能是您没有用Zero参数编写Controller默认控制器。
或者您还没有使用[HttpPost]属性
编写控制器如果你把控制器的代码放在这里会很容易。
答案 1 :(得分:0)
如果您说最后使用/ 1的导航有效,但您当前的网址没有数字,那么您在索引页面上的网址是错误的。 您的网址现在就像
@Html.ActionLink("Details", "Place")
将其更改为:
@Html.ActionLink("Details", "Place", new { id = @Model.Id })
所以问题是您的ID没有提供给您的详细信息。