PRG在ASP.NET MVC而是转移到重定向操作对象数据 [英] PRG in ASP.NET MVC but with object data transferred to the redirected action

查看:135
本文介绍了PRG在ASP.NET MVC而是转移到重定向操作对象数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继后重定向,获得在最详细的<一个在各个景点描述,但也许格局href=\"http://stephenwalther.com/blog/archive/2008/06/20/asp-net-mvc-tip-6-call-redirecttoaction-after-submitting-a-form.aspx\"相对=nofollow>这里由斯蒂芬·沃尔特,我想用 RedirectToAction 但它不会接受一个参数发送对象给它。我只能发送路由值无论是作为一个对象或作为 RouteValueDictionary 。所以目前我发送对象ID和类型,并在行动再次拉对象从数据存储的,而我重定向(如结果)。

Following the Post-Redirect-Get pattern as described in various spots but maybe in most detail here by Stephen Walter, I want to use RedirectToAction but it does not accept a parameter for sending an object to it. I can only send route values either as an object or as a RouteValueDictionary. So currently I send object ID and type and pull the object out of the datastore again in the action to which I redirected (like Results).

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

不过,我想有发送对象,因为我已经在我的更新控制器操作,所以我不需要再拉出来。

But I would like to send an object there because I already have it in my updating controller action so I don't need to pull it out again.

这是可能以某种方式?

推荐答案

请参阅这里

但我会建议通过刚刚ID。如果以后决定使用延迟加载,保持实体会议将失败(因为会话重定向后消失)。我这个经历过自己,不得不重写许多动作。

But I would recommend to pass just ID. If you later decide to use lazy-loading, keeping entity in session will fail (because session is gone after redirect). I experienced this myself and had to rewrite many actions.

这篇关于PRG在ASP.NET MVC而是转移到重定向操作对象数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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