开发者

Session State is erased after calling RedirectToAction() in ASP.NET MVC 3

开发者 https://www.devze.com 2023-04-09 11:06 出处:网络
I use a simple sequences: Set a Session State in [HttpGet] method. Redirect to another action using RedirectToAction() in [HttpPost] method.

I use a simple sequences:

  1. Set a Session State in [HttpGet] method.
  2. Redirect to another action using RedirectToAction() in [HttpPost] method.
  3. Want to get the value of that Session State, in the destination.

Problem:

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);开发者_StackOverflow中文版
        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);
    }

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?!


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

0

精彩评论

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

关注公众号