日期:2014-05-17 浏览次数:20514 次
/// <summary>
/// 更新博文点击数
/// </summary>
/// <param name="id">博文ID</param>
/// <returns></returns>
public bool UpdateArticleCount(int id)
{
var article = db.Articles.Find(id).Hits += 1;
return db.SaveChanges() > 0;
}
public ActionResult Read(int id =0)
{
Article item = db.Articles.Find(id);
if (item == null)
{
return HttpNotFound();
}
UpdateCount uc = new UpdateCount();
uc.UpdateArticleCount(id);
return View(item);
}
[/code]
using (var db = new ...)
{
var article = db.Articles.Find(id).Hits += 1;
return db.SaveChanges() > 0;
}
}[code=csharp]