0

Converting a regular ASP.NET site to MVC and I'm running into an issue with functionality that's easy in the existing site but confounding in MVC. The registration process, once completed, redirects to the Login page, passing the username and password, which logs in the user and displays a terms page since it's the first time the user is logging in.

The Login view in the MVC project has a Post action which does this:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Login(Login login)
{
   ...
   if (!u.TermsAccepted)
      return RedirectToAction("AgreementPage", "Login");
}

I need the Registration controller to use this, but there doesn't appear to be a way to call a Post action from a different controller. The best I've been able to do is display the Login view, filling in the username and password. Any way to do this in MVC?

edit:

Should have added that the Login controller also has a Get:

[HttpGet]
public ActionResult Login()
{
   ViewBag.ErrorMessage = "";
   return View();
}

Using RedirectToAction calls this, not the Post:

Login login = new Login() { Username = info.UserInfo.UserName, Password = info.UserInfo.Password };

return RedirectToAction("Login", "Login", login);
Jim Perry
  • 435
  • 1
  • 3
  • 13

1 Answers1

0

sorry for confusing you here is answer

MVC do not support post for redirect

answer

Serg Shevchenko
  • 662
  • 1
  • 5
  • 21
  • Thanks for the reply. This doesn't work, however. The version of the method you used doesn't work at all. The overload with both action name and controller name needs to be used to find the action. I've edited the original post to explain the problem in more detail. Using RedirectToAction also adds the username and password to the URL, which is not acceptable. – Jim Perry Oct 18 '18 at 14:44