I would like to know how to display the value of a property within a textboxfor
. I have the following code:
@model Calcular.Models.Conta
@{
ViewBag.Title = "Somar";
}
<h2>Somar</h2>
@using (Html.BeginForm("Action", "Conta")) {
<table>
<tr>
<td>@Html.TextBoxFor(m => m.Num1)</td>
</tr>
<tr>
<td>@Html.TextBoxFor(m => m.Num2)</td>
</tr>
<tr>
<td><input type="submit" name="Somar" value="Somar"/></td>
<td><input type="submit" name="Subtrair" value="Subtrair"/></td>
</tr>
<tr>
<td>@Html.TextBoxFor(m => m.Result)</td>
</tr>
</table>
}
Controller:
[HttpPost]
[HttpParamAction]
public ActionResult Somar(Conta conta)
{
conta.Somar(conta.Num1, conta.Num2);
return View("Somar", conta);
}
[HttpParamAction]
[HttpPost]
public ActionResult Subtrair(Conta conta)
{
conta.Sub(conta.Num1, conta.Num2);
return View("Somar", conta);
}