I recently started a project on MVC 5 and I am trying to use the javascript API from Arcgis. I used the API before in webforms in aspx pages and just normal html and it worked as expected. I amnow trying to use the same API in Razor views as i require other information to be posted from my Controllers. The question is i tried using the javascript references



and the same code from the samples they provide for javascript but require() in the cshtml page return undefined but on webpages (.aspx) it returns the desired results. I just want to know am i missing something or is the javascript api not compatible with MVC razor pages.

This is the sample code as it return undefined.

require([ "esri/Map", "esri/views/MapView", "esri/layers/ImageryLayer", "esri/layers/support/RasterFunction" ],

                function (
                    Map, MapView, ImageryLayer,
                ) {
                     * Set up popup template of image layer

                    var imagePopupTemplate = { // autocasts as new PopupTemplate()
                        title: "Data from {SensorName} satellite",
                        content: "Rendered RGB values: <b>{Raster.ServicePixelValue} </b>" +
                            "<br>Original values (B, G, R, NIR): <b>{Raster.ItemPixelValue} </b>"

                     * Create image layer with server defined raster function templates

                    var serviceRFT = new RasterFunction({
                        functionName: "TorontoFalseColor",
                        variableName: "Raster"

                    var layer = new ImageryLayer({
                        url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Toronto/ImageServer",
                        renderingRule: serviceRFT,
                        popupTemplate: imagePopupTemplate

                     * Add image layer to map

                    var map = new Map({
                        basemap: "hybrid",
                        layers: [layer]

                    var view = new MapView({
                        container: "viewDiv",
                        map: map,
                        center: { // autocasts as esri/geometry/Point
                            x: -8836932.6501,
                            y: 5411004.902699997,
                            spatialReference: 3857
                        zoom: 13,
                        popup: {
                            actions: []
  • I've been able to use the JavaScript API in Razor views, and it behaves exactly like regular HTML. Can you post a little more of your source? – Bill B Feb 25 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.