0
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);
}
Where’s the Get method of your application?
– Hans Miller
I wanted to pass two values typed by the user, do the operation and return the value to another text box. I managed to do with Viewbag
– Paulo Henrique
you can try using @Html.Editorfor() instead of @Html.Textboxfor()
– Levy Furst Neto