0

I am using c# and ASP.NET MVC4 for a web application (with mobile template). I'm having a problem with my Details view page. (First you select something from Index page and then it goes to Details page) I have put a bing map on the page and the map doesn't load. First I thought it was something wrong with the map but its not. I noticed that the url is http://localhost:2550/Place/Details of the page. However if I manually put a '1' on the end like so http://localhost:2550/Place/Details/1 then the map loads on the page. I don't understand why this is...

does anyone know why? thanks

my view page for Details:

@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>

}

my controller action for Details:

    public ViewResult Details(int id)
    {
        ViewBag.events = eventRepository.PlaceEvents(id);
        return View(placeRepository.Find(id));
    }
4

2 回答 2

1

可能的原因,可能是您没有编写带有零参数的控制器默认控制器。

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

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

于 2013-03-13T09:32:37.607 回答
0

如果您说末尾带有 /1 的导航有效,但您当前的 url 没有数字,那么您在索引页面上的 url 是错误的。您的网址现在类似于

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

把它改成这样:

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

所以问题是您的 id 没有提供给您的 details 操作。

于 2013-03-13T09:59:21.880 回答