d3.json不从ASP.NET MVC的App_Data文件夹加载文件

问题描述 投票:0回答:1

我需要从ASP.NET MVC的“App_Data”文件夹加载Geojson文件,并在d3.json中使用它。

d3.json("@Server.MapPath("~/App_Data/data/afile.geojson")", function (error, geodata) {
    if (error) return console.log(error);

    features.selectAll("path")
        .data(geodata.features)
        ...
}

我看到了错误:

error { target: XMLHttpRequest, isTrusted: true, lengthComputable: false, loaded: 0, total: 0, currentTarget: XMLHttpRequest, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, … }

在“查看页面源”中:

d3.json("C:\Users\user\Documents\Visual Studio 2013\Projects\ASP.NET\app\app\App_Data\data\afile.geojson", function (error, geodata) {
    if (error) return console.log(error);
    ...
}

怎么解决这个?

asp.net-mvc d3.js geojson
1个回答
0
投票

下面的代码应该添加到Web.config(而不是web.config)。

<system.webServer>
  <staticContent>
    <mimeMap fileExtension=".geojson" mimeType="application/geojson" />
  </staticContent>
</system.webServer>

在名为“Data”的文件夹中使用文件。

d3.json("/Data/geo/afile.geojson", function (error, geodata) {

... }

我在使用“App_Data”文件夹时看到错误。

d3.json("/App_Data/geo/afile.geojson", function (error, geodata) {

... }

© www.soinside.com 2019 - 2024. All rights reserved.