I use this to calculate sum of the two numbers:
@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>
And my controller:
public ActionResult Calculate(FormCollection values)
{
var num1 = Convert.ToInt32(values["num1A"]);
var num2 = Convert.ToInt32(values["num2A"]);
return Content((num1 + num2).ToString());
}
But it show me the result in a new page but I want to show the result in the same page. The solution was suggested to me in this question.