您需要点击产品链接并加载详细信息页面。有很多方法可以做到这一点。其中一个最简单的方法是在点击链接和加载详细信息页面之间有一种方法。因此,我可以建议的最简单的解决方案是在详细信息页面上执行操作(如果是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"}))
当你点击的项目
,你重定向到另一个页面,您可以在其中加载产品的详细信息,对吗?你必须增加那里的相关方法的计数 –
@AshkanSirous如果我设置了计数,那么它的值会在每个页面上增加1次刷新,我不想要。只有在唯一的要求时才应该增加。什么是从客户端定义唯一请求的方法? – SUN