实施上次访问的功能 [英] Implement last visited feature

查看:48
本文介绍了实施上次访问的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个MVC Web应用程序.我需要实现一个控件,该控件将在页面中显示所有最近的活动.例如,如果用户单击按钮,链接或打开新页面或选项卡,则将记录所有活动并将其显示在控件中.我可以使用活动过滤器对Controller中的每个动作进行记录,并使用ajax调用记录页面是否未刷新.但是,这似乎不可行.此功能几乎类似于Facebook中的更新"部分. MVC中还有其他方法吗?

Hi All, I have a MVC web application. I need to implement a control which will show all the recent activities in the page. For example, if a user click a button, link or open a new page or tab all activities will be logged and will be shown in the control. One thing I can use the Activity filter to each action in the Controller to log the event and use a ajax call to log if page does not get refreshed. However it seems does not feasible. This feature is almost like the update section in the facebook. Is there any other approach in MVC ?

推荐答案

MVC是不相关的.每次请求页面时,都可以通过从您自己的基类派生所有控制器来将其存储在数据库中,该基类将为用户存储此信息.
MVC is irrelevant. Every time a page is requested, you can store in the DB that it was, by deriving all your controllers from your own base class, which stores this information on the way through for the user.


您应该通过使用数据库来优化以下解决方案,快速而肮脏的方法如下. (注意:不要将以下方式用于生产应用程序,这只是出于演示目的,请使用数据库而不是示例中使用的会话)

在控制器中的每个动作上,在顶部添加以下行.

You should optimize the following solution by using database, the quick and dirty way is as follows. (Note: do not use the following way for production application, this is just for demo purpose, use database instead of session used in the example)

on every action in the controller add the following line at the top.

Session['RecentActivity'] = Session['RecentActivity'].ToString() + ViewContext.Controller.ValueProvider["action"].RawValue + "-" +
ViewContext.Controller.ValueProvider["controller"].RawValue + "<br />";



并创建局部视图并添加以下内容,然后在每个视图中呈现该视图,或者仅将以下行添加到每个视图的顶部.



and either create a partial view and add the following and then render the view in each view, or just add the following line to top of each view.

<p> @Session["RecentActivity"].ToString() </p>



我已经注意到对代码进行了测试,因此只需在少量动作和少量视图中添加代码即可对其进行测试.



I have note tested the code, so just test it by adding it on few actions and few views.


这篇关于实施上次访问的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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