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');
            },
        })
    });
3
  • Possible duplicate of How do you request static .html files under the ~/Views folder in ASP.NET MVC? Commented Feb 6, 2018 at 9: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. Commented Feb 6, 2018 at 9:08
  • Why not just use a controller action in a cshtml file? Commented Feb 6, 2018 at 9:09

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.