one of the method.
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult PostActionMethod()
{
string a = Request["txtA"];
string b = Request["txtb"];
int a1, b1;
int.TryParse(a, out a1);
int.TryParse(b, out b1);
int c = a1 + b1;
ViewBag.Value = c;
return View("Index",c);
}
}
@using (Html.BeginForm("PostActionMethod", "Home", FormMethod.Post))
{
@Html.TextBox("txtA");
@Html.TextBox("txtB");
<input type="submit" value="Sum" />
}
Result: <h1>@ViewBag.Value</h1>