Is there a way to use an actual MVC view and model to create an Html file?

There are a couple of "requirements":

1) The application must generate static HTML files from razor markup.

2) The controller in achieving (1), needs to use views and models that are already defined in application.

I understand that RazorEngine can combine a trivial template and a model as a string containing Html:

string template = "Hello @Model.Name! Welcome to Razor!";   
string result = Razor.Parse(template, new { Name = "World" });

The documentation doesn't say much but the issue here is that this doesn't go far enough. I want the Parse method to either accept:

a) the name of a view known to the controller or

b) the path of the view.

Is there a way to use an actual MVC view and model to create an Html file? A working example would be appreciated.


b) the path of the view.

If you know the path of the view, you could read its contents:

string viewPath = "...";
string template = File.ReadAllText(viewPath);

and then as the documentation states you could use the Razor Engine to pass a model and the contents of the view to get the markup:

string result = Razor.Parse(template, new { Name = "World" });
链接地址: http://www.djcxy.com/p/65100.html

上一篇: RazorEngine 3.4.1.0在AWS EC2中缓慢

下一篇: 有没有办法使用实际的MVC视图和模型来创建一个Html文件?