带参数的 RedirectToAction [英] RedirectToAction with parameter

查看:31
本文介绍了带参数的 RedirectToAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从锚点调用的动作,Site/Controller/Action/ID,其中 ID 是一个 int.

稍后我需要从控制器重定向到相同的操作.

有没有聪明的方法来做到这一点?目前我将 ID 藏在临时数据中,但是当你返回后再次按f5刷新页面,临时数据没了,页面崩溃了.

解决方案

您可以将 id 作为 RedirectToAction() 方法的 routeValues 参数的一部分进行传递.

return RedirectToAction("Action", new { id = 99 });

这将导致重定向到站点/控制器/操作/99.不需要临时或任何类型的视图数据.

I have an action I call from an anchor thusly, Site/Controller/Action/ID where ID is an int.

Later on I need to redirect to this same Action from a Controller.

Is there a clever way to do this? Currently I'm stashing ID in tempdata, but when you hit f5 to refresh the page again after going back, the tempdata is gone and the page crashes.

解决方案

You can pass the id as part of the routeValues parameter of the RedirectToAction() method.

return RedirectToAction("Action", new { id = 99 });

This will cause a redirect to Site/Controller/Action/99. No need for temp or any kind of view data.

这篇关于带参数的 RedirectToAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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