日期:2014-05-17 浏览次数:20421 次
客户端:
<script type="text/javascript">
$(function () {
window.setTimeout(function () { $.post('@Url.Action("UpdateHit", "Articles")', { _id: "@Model.CurrentArticle.Id" }); }, 5000);
});
</script>
服务器端:
[HttpPost]
public ActionResult UpdateHit()
{
int id;
if (int.TryParse(Request.Form["_id"], out id) && Request.IsAjaxRequest())
{
var uri = Request.UrlReferrer;
var url = Request.Url;
if (uri != null && url != null && uri.Host == url.Host)
ArticlesDal.UpdateTimesViewed(id);
}
return null;
}