MVC3...每次卸载视图时保存模型
我有一个 C#.NET Web 应用程序,并且希望在用户离开视图时保存我的底层模型。我正在使用带有 DbContext 对象的 .Net 实体框架。如何实现“导航保存”?
I have a C#.NET web app and would like to save my underlying Model anytime the user navigates off a View. I am using the .Net Entity Framework witha DbContext object. How would I implement a Save on Navigation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你可以通过ajax定期“保存”,所以一旦用户离开页面,它就全部保存了。
I think you could make periodically "saves" via ajax, so once the user leaves the page, it has all saved.
所有...感谢您的评论。这是有教育意义的。使用提供的有关表单和帖子的信息,我使用按钮进行发布并研究它们的价值来决定执行什么操作。
在具有导航链接的视图上,我交换了输入按钮并使用 CSS 使它们的外观和行为类似于超链接。
任务控制器
将“NavSave”作为编辑[POST]...的参数,其值为“创建子任务”或“删除子任务”。在控制器中,我检查“NavSave”是否为空......如果不是,则检查该值。如果“创建子任务”,我将保存任务模型并导航到子任务 Create[GET] 方法。如果是“DeleteSubTask”,我会保存任务模型并导航到子任务删除 [GET] 方法。为了做到这一点,我还有一个包含子任务 ID 的隐藏字段......因此,当我导航到删除 [Get] 方法时,我知道要删除哪个子任务。
喜欢的话就给个评论吧...
All....thanks for the comments. It was educational. Using the info provided regarding forms and posts, I used buttons to do poast and investigated their valuse to decide what action to perform.
On the Views that had navigation links, I swapped in the input buttons and used CSS to make them look and act like hyperlinks.
and
The Task Controller has "NavSave" as a parameter into the Edit [POST]....and the value is either "Create SubTask" or "Delete SubTask". In the controller, I check if "NavSave" is null or not....if not, I then examine the value. If "Create SubTask", I save the Task Model and navigate to the Subtask Create[GET] method. If "DeleteSubTask", I save the Task Model and navigate to the Subtask Delete[GET] method. In order to do this, I also have a hidden field containing the SubTask id....so when I Navigate to the Delete[Get] method, I know which SubTask to delete.
Give comments if you like...