2013-03-13 48 views
0

我正在使用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)); 
    } 
+1

请发表您的详细行动和观点! – nemesv 2013-03-13 09:29:56

回答

1

可能的原因,可能是你没有写控制器默认的控制器与Zero的论点。

,或者你没有写有[HttpPost]属性控制器

会很容易,如果你把代码这里控制器。

0

如果您说最后/ 1的导航有效,但当前网址没有数字,那么您的索引页上的网址是错误的。 您的网址是现在像

@Html.ActionLink("Details", "Place") 

改变它的东西是这样的:

@Html.ActionLink("Details", "Place", new { id = @Model.Id }) 

所以问题是,你的ID是不是给你的细节动作。

+0

这是我在我的索引页面中进入Details页面的内容:@using(Html.BeginForm(“Details”,“Place”,FormMethod.Post)) {

Please choose a place: @Html.DropDownList("id", (SelectList)ViewBag.placeDDL, "Choose...")
} – archie 2013-03-13 10:07:06

+0

如果您想浏览,为什么要张贴表单?将您的代码更改为超链接或处理onchange javascript事件以导航至特定页面。这样,你也可以使用url来到那个详细页面。 – 2013-03-13 10:12:31

+0

,因为详细信息页面显示所选地点的地址等,从下拉列表中选择 – archie 2013-03-13 10:25:42