我有一个网址,上面写着 www.test.com/12345。当用户点击这个 url 时,他应该被重定向到相应的操作方法,其中 "12345" 接受作为其参数。
我有一个可以与 RouteConfig 一起使用的小想法,但仍然没有清晰的画面。
有人可以帮我吗?
动作方法是
[HttpPost]
public ActionResult DetailsByCode(string code)
{
IEnumerable<IProductListDto> prdctListDto = _productListDetails.GetProductListByCode(accessCode);
Return "success";
}
并且 routeconfig 是
routes.MapRoute(
name: "Accesscode",
url: "{Areas}/{controller}/{action}/{id}",
defaults: new { Areas = "Student", controller = "Student", action = "DetailsByCode", id = string.Empty }
);
我完整的 routeconfig.cs 是
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "DetailsByCodeRoute",
url: "{Areas}/{controller}/{action}/{id}",
defaults: new { Areas = "Student", controller = "Student", action = "DetailsByCode" }
);
routes.MapRoute(
name: "Accesscode",
url: "{Areas}/{controller}/{action}/{id}",
defaults: new { Areas = "Student", controller = "Student", action = "DetailsByCode", id = string.Empty }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "ChangePassword",
url: "{Areas}/{controller}/{action}/{id}",
defaults: new { Areas = "User", controller = "User", action = "ChangePassword", id = string.Empty }
);
routes.MapRoute(
name: "PasswordReset",
url: "{Areas}/{controller}/{action}/{id}",
defaults: new { Areas = "User", controller = "User", action = "PasswordReset", id = string.Empty }
);