我这样写了我的路线。
routes.MapRoute(
name: "AdminECommerce",
url: "Admin/ECommerce/{controller}/{action}/{id}",
defaults: new { id = UrlParameter.Optional },
namespaces: new []{ "AdminEcommerce.Controllers" }
);
routes.MapRoute(
name: "ECommerce",
url: "ECommerce/{controller}/{action}/{id}",
defaults: new { id = UrlParameter.Optional },
namespaces: new []{ "Ecommerce.Controllers" }
);
routes.MapRoute(
name: "User",
url: "Plugin/User/{controller}/{action}/{id}",
defaults: new { id = UrlParameter.Optional },
namespaces: new []{ "User.Controllers" }
);
routes.MapRoute(
name: "UserRegistration",
url: "Plugin/UserRegistration/{controller}/{action}/{id}",
defaults: new { id = UrlParameter.Optional },
namespaces: new []{ "UserRegistration.Controllers" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
当我想RedirectToAction
在同一个控制器中从一个动作使用到另一个动作时,它会重定向到其他地方。
例如,我希望它把我重定向到
Plugin/UserRegistration/Register/Register
但是,它把我送到
Admin/ECommerce/Register/Register
我不得不提到我的控制器在其他库中。
我的代码有什么问题?
更新:控制器Registration
public ActionResult Register()
{
ViewBag.securityQuestions = _dataRepository.GetContext().User_SecurityQuestion;
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult RegisterNewUser(User_User model, FormCollection collection)
{
try
{
// register new user
...
return RedirectToAction("Register");
}
catch
{
// making error messages
...
return RedirectToAction("Register");
}
这个我也试过
return RedirectToAction("Register","Registration");
它不起作用。