我试图通过传递参数值来调用另一个动作的动作。网址正在添加/category?id=1
,但我期待/category/1
。不知道为什么发送?id=
。
return RedirectToAction(actionName: "Index", controllerName: "Category",
routeValues: new {id=id});
[HttpGet]
[Route("Admin/Category/{langID:int=0}")]
public ActionResult Index(int langId)
{
--
}
重定向后网址为Admin/Category?id=1
图路线
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "AdminPages",
url: "Admin/{controller}/{action}/{id}",
defaults: new { controller = "Category", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "CategoryEdit",
url:"Admin/{controller}/{action}/{id}",
defaults: new { controller = "Category", action = "Index", id = UrlParameter.Optional });
答案 0 :(得分:1)
将您的routeValues更改为routeValues: new { langId = id};
以匹配您的操作签名