In my ASP.NET MVC 4 project, I have a .json file in my App_Data folder containing the geographic data that I want to upload to D3.js.
So far, my working approach has been for jQuery to make an AJAX call to some controller that returns JsonResult - and if successful, storing JSON in some Javascript variable that loads in D3. This time I would like to skip the controller and request a static .json file directly from the App_Data folder.
I tried to capture the relative .json path using var url = "@Url.Content("~/App_Data/example.json")"; but the Javascript debugger overtook me with a lot of weird regex errors.
I also tried dropping the file into the Content folder to find out if the directory name matters.
var path = "@Url.Content("~/Content/example.json")"; Led toNetworkError: 404 Not Found - localhost: xxxxx / Content / u.json
var path = @Url.Content("~/Content/example.json"); Led toSyntaxError: invalid regular expression flag u: var path = / Content / example.json;
var json = $.getJSON("../Content/example.json") appears to send the request to the correct directory, but returns a 404 error. In addition, using Razor syntax to specify a relative URL works, but still 404s.- Adding mimeMap information to web.config also did not help.
My question is: is it possible to work with a JSON file stored in App_Data (or in the Content directory) using only Javascript / jQuery? In ASP.NET, is there only one way to do this? Is there a better approach to take at all?
source share