0

I have a web app built with ASP.NET 4.6.1 and uses the Razor view engine. Is it possible to execute a command that will render all my template files (.cshtml files) to static HTML?

I need static HTML files for certain steps in my build process and I can't think of how to render all my view files into html.

Ben Rondeau
  • 2,983
  • 1
  • 15
  • 21
  • There is this answer to do it on-demand https://stackoverflow.com/questions/22418176/is-it-possible-to-save-an-mvc-razor-view-into-an-actual-html-file. I don't see how this is possible for a static build process since the templates may contain dynamic data. There is also this similar answer with additional links https://stackoverflow.com/questions/12378829/is-there-an-example-on-using-razor-to-generate-a-static-html-page?rq=1. – Jasen Jul 10 '17 at 18:29

2 Answers2

0

I was thinking of something like what you are talking about, but my idea was a way to generate JS files (for building PhoneGap apps, for instance). The project was on BitBucket. The controller/view can generate the JS files necessary for executing the app, which was done by going to a URL to render the content, which you can view in the demo app. Any controller in the app marked with a special attribute gets rendered out to a target folder.

I was hoping to invest more into it but didn't get too far. However this was pretty easy to setup so I hope it can give you a starting point. At worse, you can create a process that spawns a browser to target this URL... At best, there is probably a better way to internalize the components to run "out of band."

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
0

Not sure if exist a easy solution for that. But if you really need it through the build process I suggest to create a consoleApp and call it from the build.For the console you can use the RazorEngine it compile/parse the razor for you.

Alexrgs
  • 831
  • 8
  • 20