Hy!
I have a very interesting problem. I have a button and if a user clicks on that button it will reload that page, incrementing the value which is stored in the viewbag and write it on the screen. When the user clicks on the button, the value of the number incremented only once and I don't know why. The codes are very simple:
The controller:
public ActionResult Index()
{
ViewBag.number= 0;
return View();
}
[HttpPost]
public ActionResult Index(int number)
{
ViewBag.number= number;
return View();
}
The view:
@{
int number= ViewBag.number;
number++;
}
@using (Html.BeginForm("Index","Default", FormMethod.Post))
{
@Html.Hidden("number",number)
@Html.Display("number",number);
<input type="submit" value="Ok" />
}
Thanks for your reply! :)