在ASP.NET MVC 3中调用RedirectToAction()后,会话状态被擦除 [英] Session State is erased after calling RedirectToAction() in ASP.NET MVC 3

查看:101
本文介绍了在ASP.NET MVC 3中调用RedirectToAction()后,会话状态被擦除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个简单的序列:

I use a simple sequences:

  1. 在[HttpGet]方法中设置会话状态.
  2. 使用[HttpPost]方法中的RedirectToAction()重定向到另一个动作.
  3. 想要在目的地获得该会话状态的值.

问题:

如果用户在表格"视图上单击提交"按钮,则会话中的所有数据都将被清除,并且我无法在目标操作(即表格")中获取它们.这是代码:

If user hits "submit" button on my "Table" view, all the data inside session got cleared and I can't get them in the destination action (which is "Table"). Here is the code:

   [HttpGet]
    public ActionResult Edit(string TableName, int RowID, NavigationControl nav)
    {
        if (nav != null) Session["NavigationData"] = nav;

        myService svc = new myService (_repository);
        EditViewModel model = new EditViewModel();

        model.TableDefinitions = svc.GetTableDefinition(TableName);
        model.RowData = svc.GetRowData(model.TableDefinitions.Name, RowID);

        return View(model);
    }

    [HttpPost]
    public ActionResult Edit(EditViewModel model)
    {
        MyService svc = new MyService (_repository);
        svc.SaveRowData(model.TableDefinitions.Name, model.RowData);
        return RedirectToAction("Table");
    }

    public ActionResult Table(string TableName)
    {
        myService svc = new myService (_repository);

        TableViewModel model = new TableViewModel();
        model.TableDefinition = svc.GetTableDefinition(TableName);

        NavigationControl nav = (NavigationControl)Session["NavigationData"];
        if (nav != null)
        {
            model.NavigationControl = nav;
        }

        return View(model);
    }

和Session ["NavigationData"]在用户通过以下方式到达时始终为空:return RedirectToAction("Table"). 如果用户在编辑"视图上单击HTML链接,则Session ["NavigationData"]可以在表格"方法中恢复其值!

and Session["NavigationData"] is always null when user reaches it via: return RedirectToAction("Table"). If user hits an HTML link on "Edit" View, Session["NavigationData"] can restore its value in "Table" method!

关于发生了什么的任何想法? 谁删除会话状态?!

Any idea about what's going on? Who deletes the Session state?!

推荐答案

我的浏览器cookie已关闭,但状态未设置为无cookie.

My browser cookie was off but state was not set to cookie-less.

这篇关于在ASP.NET MVC 3中调用RedirectToAction()后,会话状态被擦除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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