实体的持久性不止一步(ASP.NET MVC 4)(Persistence of entity in more than one step (ASP.NET MVC 4))

编程入门 行业动态 更新时间:2024-10-22 20:20:32
实体的持久性不止一步(ASP.NET MVC 4)(Persistence of entity in more than one step (ASP.NET MVC 4))

我的朋友们,我来过以前没有来过的情况。 我有一个我需要保存的实体(又名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.

更多推荐

本文发布于:2023-07-04 17:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027018.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:持久性   实体   ASP   NET   step

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!