我的朋友们,我来过以前没有来过的情况。 我有一个我需要保存的实体(又名Person;)。 但问题是,我有一组人的信息,我希望用户在多个控制器中输入,这样用户就不必填写一个表格。 他将逐步填写个人信息,学术信息,工作历史信息等表格。我正在使用MVC 4.我是否必须为每个表单/视图创建一个控制器? 因为我的实体具有所有属性,我需要立即持久化(通过我计划使用ORM的方式,尚未决定它是否将是NHibernate或实体框架)。 谢谢。
My friends, i've come trhough a situation i haven't come before. I have one entity (aka Person ;) that i need to save. But the thing is that i have groups of information of a person that i wish to ask for the user to input in more than one controller, this way the user won't have to fill a extense form. He'll go in steps filling the forms for Personal Info, Academic Info, Job History Info, etc. I'm using MVC 4. Do I have to create one controller to each form/view? Because my entity has all atributes i need to persist at once (by the way i plan to use an ORM, haven't decides if it will be NHibernate or Entity Framework yet). Thx.
最满意答案
您不需要为每个视图创建新的控制器。 这实际上不是你想要做的。 听起来你可能来自WebForms,这需要为每个表单提供不同的页面。
MVC不像这样工作。 只需为每个页面创建一个新操作和视图即可。
至于持久化数据,有很多方法可以做到这一点。 您可以使用会话数据,或者更优选地,使用数据库(模型)来存储数据。 您可以使用类似ADO.NET / Entity Framework的方法来帮助解决这个问题,这样您就不必弄乱脏数据库的详细信息。
You do not need to create a new controller for each view. That's actually not what you want to do. Sounds like you may be coming from WebForms, which would require a different page for each form.
MVC doesn't work like this. Just simply create a new action and view for each page.
As far as persisting data, there are numerous ways to do this. You can use session data, or more preferably, a database(model) to store the data. You can use something like ADO.NET/Entity Framework to help with this so you don't have to mess with the dirty database details.
更多推荐
发布评论