从装载数据库的部分美景 [英] Load Partial Views from Database

查看:170
本文介绍了从装载数据库的部分美景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,其中的局部视图的数目可以明天生长和它们可以是任何数量的值和任何类型的组合物。嗯,是的,我可以做到这一点使用部分意见本身,但我会添加新的部分添加的时候,我将需要重新编译,我想避免的应用程序。这将是非常像一个CMS,你只需指定的字段,并根据您指定的字段和它们的类型动态生成的形式。

修改1

比方说,比如你正在构建,你有多种类型的问题,并有相关的每一个类型的部分景色的调查申请。现在,如果明天你需要添加类型 - 你将如何在飞行中为新问题类型动态创建的局部视图的一个或多个问题吗?
这是这个想法在一个XML文件或数据库中,以便使你可以添加新的局部视图中的条目来自存储视图定义,你是好,而无需重新编译,以显示新的问题类型的新视图>重新启动服务器。


  

我们可以做ASP.NET MVC 5类似的东西,使用的数据存储(任何DB:SQL服务器/ MySQL的或XML文件/平面文件)?任何想法,三分球,技巧是非常AP preciated!

请纠正,如果我不正确。


解决方案

是的,你可以使用有多个值的ObjectContainer的:

的部分景色型号:

 公开名单< D​​ynamicQuestion> dynamicQuestionList {搞定;组; }公共类DynamicQuestion
    {
        公共字符串的问题得到{;组; }
        公共字符串问{搞定;组; }
    }

问心无愧的,你可以得到DynamicQuestion的列表,以便它的确定你

在分贝,你应该有一个表的问题,包含

 的id,问题

该主机的所有问题。

和一表问有

 的id,idQuestion,响应

这是保存所有要求

I'm having a requirement where the number of partial views could grow tomorrow and they could be a composition of any number of values and of any type. Well, yes, I can do this using partial views itself but the time I will add a new partial add, I will be required to recompile the application that I want to avoid. It would be very like a CMS where you just specify the fields and the form is generated on the fly based on fields and their type you specify.

Edit 1

Let's say for example you're building a survey application where you have multiple types of question and have associated partial views for every type. Now, if tomorrow you need to add one or more question types- how would you create a partial view dynamically on the fly for the new question type? This is where the idea come from to store view definitions in an XML file or in Database so that the you can just add an entry for new partial view and you're good to display a new view for new question type without re-compiling > restarting your server.


Can we do something like that in ASP.NET MVC 5 using a data store (Any DB: SQL Server / MySQL or XML File / Flat File)? Any thoughts, pointers, tips are highly appreciated!

please correct if I'm incorrect.

解决方案

Yes you can use a objectContainer that has multiple values:

Model of partial views:

public List<DynamicQuestion> dynamicQuestionList { get; set; }

public class DynamicQuestion
    {
        public string question{ get; set; }
        public string ask{ get; set; }
    }

wth that that you can get a List of DynamicQuestion so it's ok for you

in Db, you should have a table "question" that contains

id, question

that host all questions

and a table "ask" that has

id, idQuestion, response

that save all ask

这篇关于从装载数据库的部分美景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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