MVC 映射 - RedirectToAction 不起作用
我有一个 MVC 项目,将默认映射更改为:
routes.MapRoute("Default", "{controller}/{id}/{action}/{arg}",
new { controller = "Home", action = "Index",
id = UrlParameter.Optional, arg = UrlParameter.Optional }
);
以下控制器:
/Controllers/HomeController.cs:
public ActionResult Index(int? id)
{
return RedirectToAction("Index", "EPOS");
}
/Controllers/EPOSController.cs:
public ActionResult Index(int? id)
{
return View();
}
正在命中断点在 HomeController 中但没有在 EPOSController
中命中,我收到此错误:
路由表中没有路由与提供的值匹配。
我做错了什么?
I have an MVC Project witch the default Mapping whcih I changed to:
routes.MapRoute("Default", "{controller}/{id}/{action}/{arg}",
new { controller = "Home", action = "Index",
id = UrlParameter.Optional, arg = UrlParameter.Optional }
);
following Controllers:
/Controllers/HomeController.cs:
public ActionResult Index(int? id)
{
return RedirectToAction("Index", "EPOS");
}
/Controllers/EPOSController.cs:
public ActionResult Index(int? id)
{
return View();
}
A breakpoint is being hit in the HomeController but isn't hit in the EPOSController
, I get this error:
No route in the route table matches the supplied values.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信问题是因为您的
Default
路线不正确:您不能在必需参数之前添加可选参数。如果将上面的路由改为这样会发生什么?
I believe the problem is because your
Default
route isn't correct:You can't have an optional parameter preceeding a required parameter. What happens if you change the above route to this?
我认为 Shark 是对的,尝试将你的路线图分成两个像这样的定义(我还没有测试过这个)
I think Shark is right, try splitting your Route Map into two definitions something like this (I have not tested this)