简体   繁体   English

在动态页面上设置页面数并在数据库中维护页面访问数

[英]Set page count on dynamic pages & maintain page visit count in database

I just want to know the logic of this. 我只想知道这个的逻辑。 I am not posting any code because I don't know what is the logic behind this so please pardon. 我没有发布任何代码,因为我不知道背后的逻辑是什么,所以请原谅。 I have a page call dynamicPage. 我有一个页面调用dynamicPage。 This page is connected with database & everytime details of particular things gets fetched according to users selected. 该页面与数据库连接,并且每次根据选定的用户获取特定事物的详细信息。 Now I want to track How many time particular thing is visited. 现在,我想跟踪特定事物被访问了多少次。

eg 例如

  1. Hospital1 医院1
  2. Hospital2 医院2
  3. Hospital3 医院3

If user clicks on Hospital2 then it's count get increased by one & so on.. 如果用户单击Hospital2,则计数增加1,依此类推。

I made this site http://www.brandstik.in/Music here many products are listed. 我在此网站http://www.brandstik.in/Music上列出了许多产品。 Now I want to see how many times particular products is viewed. 现在,我想查看特定产品的浏览次数。

You need something between clicking on the product link and loading the detail page. 您需要在单击产品链接和加载详细信息页面之间进行操作。 There are lots of ways to do that. 有很多方法可以做到这一点。 One of the easiest ones is to have a method between you clicked on the link and loading the detail page. 最简单的方法之一是在单击链接和加载详细信息页面之间使用一种方法。 So the simplest solution that I can suggest is to have an action (if it is MVC) or a simple method on detail page, increase the count and then redirect to the original one. 因此,我建议的最简单的解决方案是在详细信息页面上执行操作(如果是MVC)或简单的方法,增加计数,然后重定向到原始页面。 So lets say your code is in MVC and you have a method like this on dynamic page: 因此,假设您的代码在MVC中,并且在动态页面上有这样的方法:

@Html.ActionLink("@item.productName", "Index", "Products", new {id = "@item.id"}))

and you have this code in your products controller: 并且您的产品控制器中有以下代码:

public class ProductsController:Controller
{
  Public ActionResult Index(int Id)
  {
  ...some code to load and return the productDetails
  }
}

Then you need to add a method to add to the count and then redirects to the original method. 然后,您需要添加一个方法以添加到计数中,然后重定向到原始方法。 so your controller will be like this: 因此您的控制器将如下所示:

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});
   }
}

And then on the dynamic page view change your code to call the new method instead: 然后在动态页面视图上,更改代码以改为调用新方法:

@Html.ActionLink("@item.productName", "IncreaseProductCount", "Products", new {id = "@item.id"}))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM