0

I am adding static help pages to my MVC application.

Clicking the help link directs to an Action Method with a unique identifier, telling the controller which page to show.

I know it can be done from within the View using Javascript or an anchor tag.

You can also open the static page from the controller, but it does not open in a new tab:

var result = new FilePathResult("~/Help/index.html", "text/html");
return result;

I cannot seem to open this static page in a new tab from the controller. Is this even possible?

EDIT

As to why How do you request static .html files under the ~/Views folder in ASP.NET MVC? does not solve my problem:

My static file do not live in the Views folder and it also does not address opening the page in a new tab.

EDIT 2 - Solution

Since this cannot be done directly from the controller I implemented the following in my View's scripts.

$('#linkAppHelpButton').off().on('click', function () {
        $.ajax({
            type: "GET",
            url: '@Url.Action("ReturnHelpPage", "Help", null)',
            data: { identifier: "index" },
            success: function (page) {
                window.open(page, '_blank');
            },
        })
    });
NightOwl888
  • 55,572
  • 24
  • 139
  • 212
Neill
  • 711
  • 2
  • 13
  • 32
  • Possible duplicate of [How do you request static .html files under the ~/Views folder in ASP.NET MVC?](https://stackoverflow.com/questions/17949460/how-do-you-request-static-html-files-under-the-views-folder-in-asp-net-mvc) – Marco Feb 06 '18 at 09:02
  • My static files do not live in the Views folder, and that link also does not talk about opening the page in a new tab. – Neill Feb 06 '18 at 09:08
  • Why not just use a controller action in a cshtml file? – Marco Feb 06 '18 at 09:09

1 Answers1

1

Since controllers are processed on the server side, it is not possible to control aspects of the browser such as "open in a new tab".

You can (as you have discovered) serve an HTML file through a controller action or just allow the web server to serve it directly. But the only options for opening the content in a new tab are to use <a target="_blank" href="some URL">new tab</a> or use JavaScript.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
  • Thank you, it seems it cannot be done directly through the controller. Have implemented an Ajax call that return the details. See Edit 2 for solution. – Neill Feb 06 '18 at 09:27