Search code examples
asp.net-mvcconvention-over-configur

Serving static content to my action using MVC's convention approach


I'm looking at outsourcing some in-page help on a large web application I am creating and would like to make it really easy for this content to added to our pages when we're ready for it.

So I was thinking I could create a system where I can add text files to the same folder where an action expects it's view to be and read out the content of that file the content in that file can be passed back to the view to display. Either that or create a helper that would do the same.

Example

Controllers
   HomeController.cs

Views
   Home
      Index.aspx
      Index.txt

Index.aspx would then have access to the content in Index.txt.

How would I start going about creating this system. Are there any built in classes in .NET MVC that I could take advantage of?


Solution

  • A similar question was asked yesterday: Including static html file from ~/Content into ASP.NET MVC view.

    Basically you can read the text from the file and include it inside your view by using File.ReadAllText so you would have something like this inside your index.aspx file

    <%= File.ReadAllText(Server.MapPath("~/Views/Home/index.txt")) %>