问题描述
我期待在构建Web配置的布局引擎,并且想直接使用剃刀引擎罩下。
I am looking at building a web configurable layout engine, and would like to directly use the razor engine under the hood.
可以说我有一些通过类,XML或数据库资料 - 我想将其转换为本地剃刀code 在运行时(我的意思是暗示我的源限定的内容和结构是基于提供者模型)。不是每个请求转换成动态XML文件或东西,我想我可能也只是写剃刀,并让该视图引擎打理一切。
Lets say I have some information available via classes, xml, or a database - I want to convert that into native razor code at runtime (by this I mean to imply my source of defining content and structure is based on a provider model). Rather than convert an xml file or something on the fly every request I figured I might as well just write Razor, and let that view engine take care of everything.
我可以插剃刀code直接进入从源的引擎,而不是文件系统?
Can I plug razor code directly into the engine from a source that is not the file system?
会不会有什么陷阱,如果我动态生成在运行时.cshtml视图和布局到文件[和动态设置在控制器动作这些观点]
Will there be any gotchas if I dynamically generate .cshtml views and layouts into files at run-time [and dynamically set those views in the controller actions]?
推荐答案
这是可以做到的。剃刀将有更多的疑难杂症的时刻比传统Web表单视图引擎,但这里有一些资源:
It is possible to do. Razor will have some more gotcha moments than classic Webforms view engine but here are some resources:
http://rebuildall.umbraworks.net/2009/11/17/ASP_NET_MVC_and_virtual_views
Using自定义的VirtualPathProvider以加载有嵌入的资源部分景观
负荷的Razor视图
ASP.NET MVC load Razor view from database
您将创建一个自定义视图引擎,这将决定在何处寻找的意见。视图可以存储在文件系统上,在数据库中,或作为嵌入的资源。阅读上我提供的链接,它应该让你去!
You'll be creating a custom ViewEngine that will determine where to look for the views. Views can be stored on the file system, in the database or as an embedded resources. Read up on the links I provided and it should get you going!
这篇关于在运行时动态生成剃刀看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!