[英]Set page count on dynamic pages & maintain page visit count in database
我只想知道這個的邏輯。 我沒有發布任何代碼,因為我不知道背后的邏輯是什么,所以請原諒。 我有一個頁面調用dynamicPage。 該頁面與數據庫連接,並且每次根據選定的用戶獲取特定事物的詳細信息。 現在,我想跟蹤特定事物被訪問了多少次。
例如
如果用戶單擊Hospital2,則計數增加1,依此類推。
我在此網站http://www.brandstik.in/Music上列出了許多產品。 現在,我想查看特定產品的瀏覽次數。
您需要在單擊產品鏈接和加載詳細信息頁面之間進行操作。 有很多方法可以做到這一點。 最簡單的方法之一是在單擊鏈接和加載詳細信息頁面之間使用一種方法。 因此,我建議的最簡單的解決方案是在詳細信息頁面上執行操作(如果是MVC)或簡單的方法,增加計數,然后重定向到原始頁面。 因此,假設您的代碼在MVC中,並且在動態頁面上有這樣的方法:
@Html.ActionLink("@item.productName", "Index", "Products", new {id = "@item.id"}))
並且您的產品控制器中有以下代碼:
public class ProductsController:Controller
{
Public ActionResult Index(int Id)
{
...some code to load and return the productDetails
}
}
然后,您需要添加一個方法以添加到計數中,然后重定向到原始方法。 因此您的控制器將如下所示:
public class ProductsController:Controller
{
Public ActionResult Index(int Id)
{
//some code to load and return the productDetails
}
public ActionResult IncreaseProductCount(int Id)
{
//increase the count
return RedirectToAction("Index",new{Id=Id});
}
}
然后在動態頁面視圖上,更改代碼以改為調用新方法:
@Html.ActionLink("@item.productName", "IncreaseProductCount", "Products", new {id = "@item.id"}))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.