【发布时间】:2017-05-18 08:48:03
【问题描述】:
在我的帐户/登录控制器方法中,我有类似的内容:
var classA = GetObject(); //actual code omitted
switch(classA.PropA)
{
case 1:
return RedirectToAction("Action2", "Registration");
//more case code omitted
default:
return RedirectToAction("Index", "Registration");
}
所有情况在 switch 块中都可以正常工作,除了默认情况下它应该转到 RegistrationController 中的索引。取而代之的是,它会将我带到 localhost:port/Registration,其中省略了操作索引。
如果将 ActionName 更改为其他名称(例如 Index2),它会正常工作。如果将控制器名称更改为其他名称,也可以正常工作。
RouteConfig 是 只是创建项目时自动生成的代码,如下:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
提前致谢。
【问题讨论】:
-
RedirectToAction("Index", "Registration");执行时会发生什么? -
抱歉,我确实忘记提及了。它只是转到 localhost:port/Registration
-
你是否在 Index 操作方法上放置了调试器?
-
它根本没有进入注册/索引
-
如果你输入
localhost:port/Registration/index然后呢?
标签: c# asp.net-mvc redirecttoaction