在ASP.Net MVC的传递控制器之间的信息 [英] Passing Information Between Controllers in ASP.Net-MVC

查看:144
本文介绍了在ASP.Net MVC的传递控制器之间的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是<一个副本href=\"http://stackoverflow.com/questions/1936/how-to-redirecttoaction-in-asp-net-mvc-without-losing-request-data\">http://stackoverflow.com/questions/1936/how-to-redirecttoaction-in-asp-net-mvc-without-losing-request-data

您好,我已经进入这让我抓我的头有点问题。基本上我有一个登录页面的Login.aspx,具有用户名和密码字段,还有一个重要的小复选框。登录在登录的AccountController方法来处理。在code目前如下:

Hi, I have come into a problem which is making me scratch my head a little bit. Basically I have a login page Login.aspx , which has username and password fields, as well as an important little checkbox. The login is handled in the AccountController Login method. The code currently is as follows:

[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");
    }
}

基本上,如果该行返回重定向(RETURNURL);火灾,则它将在另一个控制器,OpenIDController结束,这是这种情况,其中sendStoredInfo布尔变得重要。但问题是我没有提到它,当我在OpenIDController我。我怎么可以在发送这个值?

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?

推荐答案

电话更改为:

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

该控制器的操作方法签名可能是这样的:

The controller action method signature could be something like:

public ActionResult LoginFailed(bool sendFlag)
{
    ...
}

这篇关于在ASP.Net MVC的传递控制器之间的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆