在Asp.Net MVC我想增加每個表單提交(按鈕點擊)的模型屬性。Asp.net MVC遞增按鈕
我試過HttpGet和HttpPost。使用HttpGet,該值始終由查詢字符串覆蓋,並且始終爲0.使用HttpPost時,值從0開始,我單擊該按鈕並將其遞增爲1.但是,再次單擊它時,它會以0和增量形式出現1。
從我的理解,它的輸入0,0 + 1 = 1,輸出0
爲了使簡單:
@using (Html.BeginForm())
{
@Html.HiddenFor(x=>x.Value) or @Html.Hidden("Value", Model.Value)
or even <input type="hidden" value="@Model.Value" />
<input type="submit" value="Click Me" />
}
public ViewResult ActionMethod(Model model)
{
model.Value++;
return View(model);
}
我的問題基本上是這樣的: Increment number per button click C# ASP.NET 但在MVC框架中。
你如何操縱這樣的模型屬性?我不想使用Javascript。
相信與否,我會盡可能地說JQuery可能是您的最佳解決方案。這只是一個非常簡單的事情,可以在沒有太多麻煩的情況下完成客戶端 – mattytommo 2012-04-20 22:30:41
您的更新解決方案是實現它的唯一方法。 MVC將使用發佈的值更新您的視圖,因此您必須清除它們。 – 2012-04-20 23:25:11