Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6126017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:19:07+00:00 2026-05-23T16:19:07+00:00

I have many static HTML files (Lets say 1.html to 100.html). Is there any

  • 0

I have many static HTML files (Lets say 1.html to 100.html). Is there any way that I can create a link like Files/get/1 (where “Files” is the controller and “get” is the action). Read the file based on the passed id and put the file’s content inside my site layout and send it to user.

In this way the format of those Html file will be preserved, and I wouldn’t need to create a View for each file.

I am new to MVC and will appreciate any suggestion/hint. Let me know if the question is not clear.

Thanks for the help in advance.
Reza,

Edit: Added what I ended up doing.

Answer: So I used what Darin said below, combined it with a little bit of jQuery and got exactly what I needed. Which was loading static HTML files inside my layout. Here is the sample of what I did:

First I created two methods in my Controller:

    public ActionResult GetHelp(String id)
    {
        var folder = Server.MapPath(Config.get().Help_Folder);
        var file = Path.Combine(folder, id + ".html");
        if (!System.IO.File.Exists(file))
        {
            return HttpNotFound();
        }
        return Content(System.IO.File.ReadAllText(file), "text/html");

    }


    public ActionResult GetHelper(String id)
    {

        ViewBag.helpPath = id; 
        return View();

    }

Then I created a view called GetHelper, which uses my layout, and added the below code to it:

<script type="text/javascript">

$(function () {
    var path = "@ViewBag.helpPath"
    path = "@Url.Content("~/Helps/GetHelp/")" + path;
    $('#help-content').load(path);

});
</script>

<div id="help-content">

</div>

And it works perfectly. The only downside is for each page we get two server requests 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:19:07+00:00Added an answer on May 23, 2026 at 4:19 pm

    Something among the lines:

    public class FileController : Controller
    {
        public ActionResult Index(string id)
        {
            var folder = Server.MapPath("~/SomePathForTheFiles");
            var file = Path.Combine(folder, id + ".html");
            if (!System.IO.File.Exists(file))
            {
                return HttpNotFound();
            }
            return Content(System.IO.File.ReadAllText(file), "text/html");
        }
    }
    

    and if you wanted the user do download those files:

    return File(file, "text/html", Path.GetFileName(file));
    

    and because those are static files you could cache them by decorating your controller action with the [OutputCache] attribute:

    [OutputCache(Location = OutputCacheLocation.Downstream, Duration = 10000, VaryByParam = "id")]
    public ActionResult Index(string id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say you have lots of html, css, js, img and etc files within
Let's say I have the three html template files shown below. HTML is minimal
I have come accross the static HTML app for facebook pages that allows us
I have a complex form that has a static section and one that can
I have many static images under a directory in my site structure, and I'm
I have a static class with no static constructor, but many static members. I
I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc.,
I have many jobs that have a step to send 1 specific email out
We have many projects that use a common base of shared components (dlls). Currently
I have many sites that use the same root category of the Main Site.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.