开发者

ASP.NET MVC : Sending information to make a RedirectToAction

I need to send data before making a "RedirectToAction" to the new view, and do not want the data being sent by "GET".

The only thing I can think of is to keep this information in session before redirecting to the new view, but I prefer to do otherwise.

Thanks.

Edit width example

public class AccountController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Login()
    {
        return View(new LoginViewModel());
    }

  开发者_StackOverflow社区  [HttpPost]
    public ActionResult Login(LoginViewModel model, string returnUrl)
    {
        if (LoginModel.Login(model)){

             UserData ud = UserData(model.IdUser);
             return RedirectToAction("Index", "Information");

        }

        // code
     }
}     

//

public class InformationController : Controller
{
    public ActionResult Index()
    {

        //receives "ud" information
        // ... 
        return View();
    }

}     


You could pass the data as a request parameter:

return RedirectToAction("Foo", new { param1 = "value1", param2 = "value2" });


I'm not sure what you are trying to achieve but TempData["yourkey"] might be what you want to use. it's not best practice though. but if you want to redirect to an action, where do you want the data to be sent to?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜