Controlling Razor views programmatically?

你说的曾经没有我的故事 提交于 2019-12-23 03:07:38

问题


Is is possible to programmatically control Razor views? Can I reach the different RenderSection parts or change the Layout definition in code?

I'm looking into possibilities to use Razor syntax in the presentation layer of a CMS application. Might Spark be a better choice because of it's (parseable) XML syntax?


回答1:


Take a look at http://razorengine.codeplex.com and http://tqcblog.com/2011/01/23/precompiled-razor-for-shared-views-and-mono/ - you can convert razor views to c# code and set the views to use a custom base class that has whatever additional functionality you need.

You may also be able do something with the viewstart file - although set up as a razor view, it is effectively custom code that modifies the settings of all views, including the layout.



来源:https://stackoverflow.com/questions/5153090/controlling-razor-views-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!