代码之家  ›  专栏  ›  技术社区  ›  mare

ASP.NET MVC中的PRG,但对象数据传输到重定向操作

  •  2
  • mare  · 技术社区  · 15 年前

    遵循Post-Redirect-Get模式,如各个点所述,但可能是最详细的 here by Stephen Walter ,我想用 RedirectToAction 但它不接受向其发送对象的参数。我只能将路由值作为对象或 RouteValueDictionary . 因此,当前我发送对象ID和类型,并在重定向到的操作中再次将对象从数据存储中拉出(如结果)。

    // redirect to confirm view
    return RedirectToAction("ChangeSuccess", "Redirect",
        new { slug = tabgroup.Slug, contentType = tabgroup.ContentType });
    

    但我想发送一个对象,因为我已经在我的更新控制器的行动,所以我不需要再把它拉出来。

    有可能吗?

    3 回复  |  直到 14 年前
        1
  •  1
  •   queen3    15 年前

    看到了吗 here .

    但我建议只传递ID,如果您稍后决定使用延迟加载,将实体保持在会话中将失败(因为会话在重定向之后消失)。我自己也经历过,不得不重写许多动作。

        2
  •  2
  •   Rippo    15 年前

    read this

    ... One of the issue with this pattern is when a validation fails or any exception occurs you have to copy the ModelState into TempData. If you are doing it manually, please stop it, you can do this automatically with Action Filters...

    它的编号是13。使用PRG模式修改数据

        3
  •  0
  •   Community CDub    8 年前

    无法将对象传递给GET URL。

    RedirectToAction 方法发布了一个新的 GET

    但是你可以通过 query string 获取URL的参数。所以请按照女王的建议通过身份证。

    为了在后续请求之间持久化您的对象,我强烈建议您使用 TempData . 但是,它在内部使用会话,但在请求后立即终止。