Custom Widget in .NET Framework Application

199
3
11-15-2021 09:22 AM
nrhill123
New Contributor

Hello,

 

I am currently developing a custom widget with the 4.21 JavaScript API with TypeScript. I am having an issue importing it into the _Layout.cshtml of my .NET Application. I put the widget directory within the custom script directory of my .NET app and compiled it according to the instructions, however, my application cannot find the script at runtime which crashes all the ESRI components of my app. Here is my index.html within the widget directory.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
    <title>Routing Widget</title>
    <script>
        let locationPath = location.pathname.replace(/\/[^\/]+$/, "");
        window.dojoConfig = {
            packages: [
                {
                    name: "app",
                    location: locationPath + "/app"
                }
            ]
        };
    </script>
    <!-- <script src="https://js.arcgis.com/next"></script>-->
    <script src="https://js.arcgis.com/4.21/"></script>
    <script>
        require(["app/RoutingWidget"]), function (RoutingWidget) {
            console.log("This is a test: ", RoutingWidget.testProp)
        };
    </script>
</head>

<body>
  <div id="viewDiv"></div>
</body>

</html>

 

0 Kudos
3 Replies
ReneRubalcava
Frequent Contributor II

Does this work outside .NET environment? I haven't used .NET to build web apps in years, it could be a file copy issue, not sure.

0 Kudos
nrhill123
New Contributor

Rene,

Thanks for your response! I have not tried it yet. 

I did some changes to my code but now I am running into a browser issue wherein I cannot access local resources within the project directory. I tried hosting it on an http-server, but I get a multiple define error with Dojo.

0 Kudos
nrhill123
New Contributor

Rene,

I installed the @types/arcgis-js-api and I have gotten the application to read the widget script, however, I am having issues with an Uncaught Reference Error: require is not defined -- which I tried to solve by switching the module setting in tsconfig to commonjs but to no avail. I am wondering what I need to add or change in my settings to get the application to be able to read my script. I also added numerous C#/NuGet packages to the main application like requirejs to try and solve the issue, but nothing seems to be working. Is there anything you can recommend?

Thanks!

0 Kudos