Designating a link open a .cshtml (view) file in a text editor

Dean Everhart 1,536 Reputation points
2023-03-24T12:26:11.8366667+00:00

Is there a way to have a .net webpage link and open a .cshtml (view) page in either in Visual Studio or other text editor?

<a href="/Views/Home/Notes.cshtml">View in Text Editor</a>

Yields

User's image

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,502 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,451 questions
{count} votes

Accepted answer
  1. AgaveJoe 28,031 Reputation points
    2023-03-24T13:58:57.8666667+00:00

    Either place the file in wwwroot or write an action/handler to return a file. Also see your other thread with the same subject.

    Path is the absolute path to the file. Keep in mind, Razor Pages are compiled into a binary.

            public async Task<IActionResult> OnPostDownloadFile()
            {
                Byte[] buffer = await System.IO.File.ReadAllBytesAsync(path);
                return File(buffer, "text/html");
            }
    

    The editor that opens the file depends on what applications are installed on the client's machine and how the default settings are configured.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.