I am attempting an ASP.NET MVC4 page that collects data from a form submits that to a web service and returns a different view which renders a map based on the results from the web service. I'm running into a problem where the view that shows the results will not render any maps. I am new to jQuery/ASP.NET so maybe I am missing something obvious.
The controller piece:
public ActionResult Project(MyProjectModel project) {
//Make web service call using project model and create a result model
...
var model = new ResultModel {Name=project.Name};
return View("Results", model);
}
The View:
@model WebApp.Models.ResultModel
@{ ViewBag.Title = "Results"; }
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/soria/soria.css">
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
<script type="text/javascript">
dojo.require("esri.map");
dojo.declare("my.MapLayer", esri.layers.DynamicMapServiceLayer, {
constructor: function () {
this.initialExtent = this.fullExtent = new esri.geometry.Extent({ xmin: 143.834824, ymin: -43.648056, xmax: 148.47914, ymax: -39.57389, spatialReference: { wkid: 4326} });
this.spatialReference = new esri.SpatialReference({ wkid: 4326 });
this.loaded = true;
this.onLoad(this);
},
getImageUrl: function (extent, width, height, callback) {
var params = {
request: "GetMap",
transparent: "true",
format: "image/png",
version: "1.1.0",
layers: "ws:@Model.JobId",
exceptions: "application/vnd.ogc.se_xml",
//changing values
bbox: extent.xmin + "," + extent.ymin + "," + extent.xmax + "," + extent.ymax,
srs: "EPSG:" + extent.spatialReference.wkid,
width: width,
height: height
};
callback("http://localhost:8080/geoserver/wms?" + dojo.objectToQuery(params));
}
})
function init() {
var map = new esri.Map("map");
map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer"));
map.addLayer(new my.MapLayer());
}
$('#output').live("pageshow", function () { alert('pageshow'); init(); });
$('#output').live("pagecreate", function () { alert('pagecreate'); });
$(document).ready(function () { alert('docready'); $("#output").live('pageshow', init); });
</script>
<div data-role="page" data-theme="b" id="output">
<div data-role="content">
<div id="map" class="soria" style="position: relative; width: 100%; height: 300px;
border: 2px solid #000;">
</div>
</div>
</div>
The map will load if I type the URL directly in the browser, however whenever I try to return it with from another controller view, the javascript events will not trigger. Is this by design or am I abusing MVC / jQuery here? Thanks for any suggestions!
.ready
method being executed at least? – Justin Helgerson May 17 '12 at 21:24$('#output')...
. You're calling that before that element exists in the DOM (it isn't rendered until you get past those lines of code). – Justin Helgerson May 18 '12 at 21:08