我将 MVC 与 Razor 和 C# 一起使用。我想更新一个元素......一个带有ajax的计数器。这是我的代码:
@model Domain.CounterObject
@using (Ajax.BeginForm("Count", "CounterObject", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "my-control" }))
{
<div id="my-control" class="bid-object">
<div>
<span class="title">@Html.Encode(Model.Title)</span>
</div>
<div>
<span class="display">@Html.Encode(Model.GetFinalDate())</span>
</div>
<div>
<span class="display">@Html.Encode(Model.GetValue())</span>
</div>
<div>
<input type="submit" value="Count" />
</div>
</div>
}
在我的控制器中,我有以下代码:
[HttpPost]
public PartialViewResult Count(CounterObject counter)
{
// Special work here
return PartialView(counter);
}
问题是我在 Count 方法中收到的 CounterObject 计数器始终为空。如何将值从我的页面传递给控制器?