2
I have a very simple form with 3 textbox and a button. I would like to take the value of the first two textbox by clicking the button and passing to a method present in my model and after that return this result to the third textbox. I’m having trouble passing the values and returning using the controller. I’m a beginner in Asp.net mvc if anyone can help. Thanks.
I have this method of Model that I want to use:
public class Conta
{
[Required]
public int Num1 { get; set; }
[Required]
public int Num2 { get; set; }
public double Result { get; set; }
public int Somar(int num1, int num2)
{
return num1 + num2;
}
This in the controller:
public ActionResult Index()
{
return View();
}
private static Conta _conta = new Conta();
[HttpPost]
public ActionResult Somar(Conta conta)
{
_conta.Somar(conta.Num1, conta.Num2);
return View();
}
And that’s on the index:
<tr>
<td>@Html.TextBoxFor(ContaModel => ContaModel.Num1)</td>
</tr>
<tr>
<td>@Html.TextBoxFor(ContaModel => ContaModel.Num2)</td>
</tr>
<tr>
<td><input type ="submit" value="Somar" name="Somar"/></td>
</tr>
</table>
As a beginner in this, I don’t know if this is the right way to do it.
Hello Paulo Henrique, could post the code you already have?
– PauloHDSousa
You can edit the question and put the code in it
– PauloHDSousa
Okay, I was able to put a part of the code in the question.
– Paulo Henrique
Angularjs (https://angularjs.org/) does not meet this need? https://www.youtube.com/watch?v=RiB0TXOhd3U
– Sileno Brito