简体   繁体   English

从ASP.NET Razor CSHTML文件渲染HTML文件

[英]Render html files from ASP.NET Razor cshtml files

I have a web app built with ASP.NET 4.6.1 and uses the Razor view engine. 我有一个使用ASP.NET 4.6.1构建的Web应用程序,并使用Razor视图引擎。 Is it possible to execute a command that will render all my template files (.cshtml files) to static HTML? 是否可以执行将我的所有模板文件(.cshtml文件)呈现为静态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. 在构建过程中的某些步骤中,我需要静态HTML文件,但我想不出如何将所有视图文件呈现为html。

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). 我当时在想类似您所谈论的内容,但是我的想法是一种生成JS文件的方法(例如,用于构建PhoneGap应用程序)。 The project was on BitBucket . 项目在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 . 控制器/视图可以生成执行该应用程序所需的JS文件,这是通过转到URL呈现内容来完成的,您可以在演示应用程序中查看该文件 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." 更糟糕的是,您可以创建一个生成浏览器来定位此URL的过程……充其量,可能是一种更好的方法来内部化组件以“带外”运行。

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. 但是如果您在构建过程中确实需要它,我建议创建一个consoleApp并从构建中调用它。对于控制台,您可以使用RazorEngine它为您编译/解析剃刀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM