I have the following problem:
On a given HTML page I have two buttons that call different POST methods on the same controller.
@using (Html.BeginForm("UserInfo1", "UserInfo", FormMethod.Post))
{
<input type="submit" value="Ir para Action"
name="botao1" id="botao1" />
}
@using (Html.BeginForm("UserInfo2", "UserInfo", FormMethod.Post))
{
<input type="submit" value="Ir para Action"
name="botao2" id="botao2" />
}
The code on my controller is as follows:
using Project1.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
namespace Project1.Controllers
{
public class UserInfoController : Controller
{
[HttpGet]
public ActionResult UserInfo()
{
return View();
}
[HttpPost]
public ActionResult UserInfo1(string g)
{
@Viewbag.User1 = g;
return View();
}
[HttpPost]
public ActionResult UserInfo2(string g)
{
@Viewbag.User2 = g;
return View();
}
}
}
The route configured for this controller is:
routes.MapRoute(
name: "UserInfo",
url: "profile/",
defaults: new { controller = "UserInfo", action = "UserInfo", id = UrlParameter.Optional }
);
The big question is that pressing the buttons is NOT being redirected to the UserInfo1 and UserInfo2 methods (I realize this when I try to perform the operation by inserting breakpoints into those methods). Consequently I get a 404 error in the HTML page.
How can I get access to each of these methods? do I need to create some kind of specific route?