我有行动
public ActionResult Edit(int id)
如果 id 为空,我需要重定向到操作索引。如何在路由中做到这一点?
我试过:
routes.MapRoute(
name: "Redirect from empty controller/edit to controller/list",
url: "{controller}/Edit",
defaults: new { controller = "Home", action = "Index" }
);
但这并没有帮助。
最佳答案
嗯,不确定路由,但如果有帮助,您可以使用 return RedirectToAction("index", "home");
(其中 index 是您的操作方法,home 是您想要的 Controller 访问它)。
关于c# - 如何通过普通路由重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18485678/