1

I've got a simple MVC web page that pops up a dialogue box with a list of hyperlinks to files. They're properly prefixed with "file://" and the links work properly if copied to the clipboard and pasted into a browser window. However, from within the dialogue, clicking on the linked files returns... nothing.

Nothing at all happens. The behavior is identical in Firefox, Internet Explorer, and Chrome. No warnings, errors, etc.

Visually my dialogue looks like this:

enter image description here

If I "inspect element" on one of the links, for example, the top one for "javascript notes.txt", it looks like this:

enter image description here

This IS a valid hyperlink. As mentioned above, I can copy the link into the address bar of a browser and the linked file opens fine. I can also copy the full HTML of the element into notepad, wrapped in tags and save as an .html file, and the link works just fine from there. The links just don't work in the dialogue--from any browser.

I'm displaying the links in a Kendo grid currently. Thinking that might be a problem, I got rid of the grid temporarily and tried displaying them in a plain HTML . Same problem--clicking on the links produces no result at all.

Am I fighting something deeper here? Like, I'm using a jquery dialogue to show the list. do jquery dialogues do something to block hyperlinks from working?

TIA for any help.

Community
  • 1
  • 1
markaaronky
  • 1,209
  • 11
  • 26
  • Sounds like an errant bit of JavaScript is actually intercepting and preventing the link click. It may have to do with the fact that it's within a grid. Not sure. But JavaScript is the only thing that explains this issue. Look for click event handlers and particularly where you might have something like `preventDefault()`. – Chris Pratt Nov 17 '16 at 18:15
  • 2
    Browser disallow links to `file://...` by default for security reasons (unless the original serving page is itself from a `file://`. To get around this, either start chrome from the command line with `--allow-file-access-from-files` (other browsers will have other command line arguments), or serve the files using MVC and regular `http://...` hyperlinks. –  Nov 17 '16 at 18:20
  • For more information, see [Firefox](http://kb.mozillazine.org/Firefox_:_Issues_:_Links_to_Local_Pages_Don%27t_Work), [Chrome](https://stackoverflow.com/questions/2087894/can-google-chrome-open-local-links), [IE](https://superuser.com/questions/149068/how-to-add-a-local-file-to-trusted-zone-in-ie8) –  Nov 17 '16 at 18:28
  • Amy's response led me to a solution (knowing file:// is blocked by default is her important clue). I can't do a browser-dependent solution as she suggests, but what I did was code a method in a controller that returns type File, and then altered my hyperlink to call that controller, passing the name of the file I want returned. There is an excellent article on returning files this way here: http://rachelappel.com/upload-and-download-files-using-asp-net-mvc/ – markaaronky Nov 18 '16 at 16:39

1 Answers1

0

As per Amy's comment on the original question, browsers seem to block the file:// links when opening from a page retrieved via http. The workaround I implemented came from the excellent article linked below: I coded a simple action method in a controller that returns not a view but a File, and changed the hyperlinks to invoke that controller method via http. Works like a charm.

see: http://rachelappel.com/upload-and-download-files-using-asp-net-mvc/

markaaronky
  • 1,209
  • 11
  • 26