我试图从视图中调用一个方法,但它不起作用!:(
我的控制器代码:
public class ProfessionalController : Controller
{
//
// GET: /Professional/
public ActionResult Index()
{
return View();
}
public ActionResult Sum(int nro1, int nro2)
{
var value = nro1 + nro2;
ViewBag.SumResult = value;
return View();
}
}
我的意见代码:
专业指数:
@{
ViewBag.Title = "Profissional";
}
<h2>Profissional</h2>
@using (Html.BeginForm("Professional", "Sum")) {
<input id="nro1" type="number" class="form-control marged_top" placeholder="Numero 1" />
<input id="nro2" type="number" class="form-control marged_top" placeholder="Numero 2" />
<button id="Sum" name="Sum" value="Sum" class="btn btn-default" type="button"
data-toggle="button">
Sum
</button>
}
总和视图:
@{
ViewBag.Title = "Sum";
}
<h2>Sum</h2>
@ViewBag.SumResult;
不会发生任何错误,当我单击 Sum 按钮时没有任何反应。