如何使用一个操作从数据库呈现视图 [英] How to use one action to render views from database

查看:104
本文介绍了如何使用一个操作从数据库呈现视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过动态创建视图来添加CMS。我找到了一个使用VirtualPathProvider类从数据库加载视图的解决方案。我已经成功完成了,我的下一个问题是我们无法为那些动态视图编写动作,任何人都可以分享他们使用一个动作渲染我的观点和内容的经验。



用简单的单词只需要创建一个通用的动作,我就可以从数据库中呈现我的观点(数据库无限制)。



我是什么尝试过:



先谢谢你们,我需要快速回复。

I have a requirement to add CMS by creating views dynamically. i have found a solution to load views from database by using VirtualPathProvider class. i have done it successfully and my next problem is we can not write actions for those dynamic views can anyone share their experience how i render my views and their content by using one action.

in simple words just need to create a common action by whom i can render my views (unlimited because of database) from database.

What I have tried:

Thanks for you guys in advance, i need q quick replies.

推荐答案

您不需要将CMS的每个页面视为每页需要单个操作,因此需要1个通用操作...而是需要将CMS分解为CMS具有的不同类型的页面每页有1个动作类型。



例如,如果你有一个CMS支持创建新闻文章,个人博客,并说...显示图片库,你不会为每个创建的画廊都有一个动作,而是y我们的CMS在CMS所需的控制器中有3个动作。



动作1 - 新闻

动作2 - 博客

操作3 - 图库



然后形成这3个操作,您将数据加载到他们尊重的模型,并相应地将该模型传递到各自的视图。



如果您以这样的方式构建它,每个页面都有自己独特的风格和格式,那么从数据库驱动的角度来看,您需要更加复杂的可定制性但就其最简单的形式而言,这就是你如何使用100页的CMS,并将其转化为3个动作。



除非您的CMS仅支持1种类型的页面(例如:博客),否则我不会建议1个通用操作。



如果你需要添加一个新的页面类型...比如个人文件夹UI,那么那将是你要添加的另一种页面类型4控制器的操作。
You need to not think of every page of your CMS as requiring a single action per page and thus a need for 1 generic action...instead you need to break down your CMS into the different types of pages your CMS has and have 1 action per page type.

For example, If you have a CMS that supports creating news articles, personal blogs, and say...displaying a picture gallery, you wouldn't have a single action for every gallery that gets created, rather your CMS would have 3 actions within the CMS's desired controller.

Action 1 - News
Action 2 - Blog
Action 3 - Gallery

Then form those 3 actions, you load the data to their respected models, and pass that model to their respective view accordingly.

If you have built it in such a way where each "page" gets its own unique style and formatting then your going to have to get more complex with customizability from a DB driven perspective but at its simplest form, this is how you can take a CMS with say, 100 pages and turn it into just 3 actions.

I would not suggest 1 generic action unless your CMS only supports 1 type of page (ex: a blog).

If you need to add a new page type...say, a personal file folder UI, then that would be another page type that you'd then add a 4 action to your controller for.


这篇关于如何使用一个操作从数据库呈现视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆