我想知道我怎么能算的时间在我看来,一个按钮使用sessions
,而不是点击使用jQuery,只是asp.net的数量。计数一个按钮被点击了多少次
这里是我的操作方法(空):
public ActionResult ClickCounter()
{
return View();
}
和我的观点:
@{
ViewBag.Title = "ClickCounter";
}
<h2>ClickCounter</h2>
@using (@Html.BeginForm())
{
<!-- form content here -->
@Session["num"] = 0;
<form method="post">
<fieldset>
<legend>Button clicks counter</legend>
<div>
<label for="Clciks">Clicks:</label>
<h2>@Session["num"]</h2>
</div>
<div>
<label> </label>
<input type="submit" value="Click!" class="submit" />
</div>
</fieldset>
</form>
}
原谅我的瘸腿的问题,但我是一个完整的新手,并试图了解如何东西工作。我试着googleing。 我只想在我的视图中使用会话来显示h2中的点击次数。
任何提示,将不胜感激。
目前'@Session [ “NUM”] = 0;'将复位计数器每次您查看该页面。尝试将'(int)Session [“num”] ++;'放在您的操作方法中。如果尚未设置会话值,则可能需要一些初始化值。 – ADyson