我用它来计算两个数字的总和:
@using (Ajax.BeginForm("Calculate", "Student", new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "Result" }))
{
<div>@Html.TextBox("num1A")</div>
<div>@Html.TextBox("num2A")</div>
<div id="Result"></div>
<input type="submit" value="CalculateWithAjax" />
}
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script src="~/Scripts/jquery-1.7.1.js"></script>
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
我的控制员:
public ActionResult Calculate(FormCollection values)
{
var num1 = Convert.ToInt32(values["num1A"]);
var num2 = Convert.ToInt32(values["num2A"]);
return Content((num1 + num2).ToString());
}
但是它会在新页面中显示结果,但我想在同一页面中显示结果。在this问题中向我建议了解决方案。