我有一个动作,我从一个锚调用,因此,站点/控制器/动作/ID,其中ID是一个int。

稍后,我需要从控制器重定向到相同的动作。

有什么聪明的办法吗?目前我在tempdata中存储ID,但当你 返回后,按f5再次刷新页面,tempdata消失,页面崩溃。


当前回答

这一行代码就可以做到:

return Redirect("Action"+id);

其他回答

RedirectToAction带参数:

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

我也有这个问题,如果你在同一个控制器中,一个很好的方法是使用命名参数:

return RedirectToAction(actionName: "Action", routeValues: new { id = 99 });
//How to use RedirectToAction in MVC

return RedirectToAction("actionName", "ControllerName", routevalue);

例子

return RedirectToAction("Index", "Home", new { id = 2});

你也可以发送任何ViewBag, ViewData..像这样

return RedirectToAction("Action", new { Dynamic = ViewBag.Data= "any data" });

这一行代码就可以做到:

return Redirect("Action"+id);