Home > DeveloperSection > Forums > Passing Information Between Controllers in ASP.Net-MVC
Goti Bandu

Total Post:119

Points:835
Posted on    May-21-2015 6:56 AM

 ASP.NET MVC Mvc4  Controller 
Ratings:


 1 Reply(s)
 527  View(s)
Rate this:

I have a login page login.aspx, which has username and password fields, as well as an important little checkbox. Login is handled in the account controller login action.

Syntax:

[AcceptVerbs(HttpVerbs.Post)]

[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", Justification =

                "Needs to take same parameter type as Controller.Redirect()")]

        public ActionResult LogOn(string userName, string password, string returnUrl,

            bool sendStoredInfo)

        {

            if (!this.ValidateLogOn(userName, password))

            {

                return View();

            }

 

            this.FormsAuth.SignIn(userName, false);

 

            if (!String.IsNullOrEmpty(returnUrl))

            {

                return Redirect(returnUrl);

            }

            else

            {

                return RedirectToAction("Index", "Home");

            }

        }

Basically, if the line return Redirect(returnUrl); fires, then it will end up in another controller, the OpenIDController, and it is that situation where the sendStoredInfo bool becomes important. But the problem is I have no reference to it when I'm in the OpenIDController. How can I send this value across?



Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    May-21-2015 7:52 AM

Change the call to:

return RedirectToAction("LoginFailed", new { sendFlag = sendStoredInfo });

The controller action method signature could be something like:

public ActionResult LoginFailed(bool sendFlag)

{

    ...

}


Don't want to miss updates? Please click the below button!

Follow MindStick